2011-04-30 3 views
1

내가 원한다. 앱 실행시 기본적으로 이미지가로드됩니다. URL을 지정하여 사용자가 원하는 다른 이미지를로드하는 방법이 있습니다. 사용자 정의 이미지가로드되면 기본 이미지는 배경에 그대로 남아 있으며 이미지 전체에 일부 필터를 적용하는 데 사용할 수있는 방법이 있습니다 (기본 이미지와 사용자가로드 한 이미지를 모두 포함하는 결과 이미지를 의미 함) 블렌드), 최종 이미지를 jpg 또는 png로 저장하려고합니다.플렉스에서의 이미지 조작에 관한 몇 가지 질문

이제 저는 Flex의 모든 초보자입니다. 모든 캔버스, 이미지 컨트롤, 비트 맵 데이터 등으로 혼란스러워하고 있습니다. 내가 원하는 것은 내가 원하는 것을 구현하는 가장 좋은 방법입니다. 기본 이미지를 url/embed가있는 이미지로로드해야합니까, 아니면 BitmapData로로드해야합니까? 두 번째 사용자 정의 이미지를로드하는 방법은 무엇입니까? 두 이미지를 혼합하는 가장 좋은 방법은 무엇입니까?

답변

0

기본 이미지를 임베드 된 이미지로 그대로두고 BitmapData을 검색하여 추가로 사용할 수 있습니다. 사용자 정의 이미지가로드되면

, 당신은 BitmapData를 검색하고 이상 포함 된 이미지를 그려 사용자 정의 하나

/** 
* An embedded image's class (your default image) 
*/ 
[Embed(source="/assets/logo.png")] 
public static var Logo:Class; 

/** 
* @param bitmapData: The user-defined BitmapData that you want to modify 
* @param matrix: The transofrmation matrix applied to the resulting BitmapData 
*/ 
public function getCustomBitmapData(bitmapData:BitmapData, matrix:Matrix):BitmapData 
{ 
    // Initialize and drawing the resulting BitmapData's first layer 
    var result:BitmapData = new BitmapData(bitmapData.height, bitmapData.width); 
    result.draw(bitmapData, matrix); 

    // Load the BitmapData of the embedded Logo image 
    var bitmapAsset:BitmapAsset = new Logo(); 
    var logoBd:BitmapData = bitmapAsset.bitmapData; 

    // Draw the logo over the result with an alpha of 0.3 
    result.draw(logoBd, matrix, new ColorTransform(1, 1, 1, .3)); 
    //TODO: You should play with the size of the images, apply filters, etc. 

    return result; 
} 

그런 다음 로컬 파일 시스템에 결과 BitmapData instace을 절약 할 수 있습니다 :

/** 
* Save the BitmapData to a local file 
* @param bitmapData: the data to save 
*/ 
public function saveBitmapData(bitmapData:BitmapData):void 
{ 
    // Initialize the encoder 
    var pngEncoder:PNGEncoder = new PNGEncoder(); 
    // Encode the BitmapData and save its byte array 
    var imageBytes:ByteArray = pngEncoder.encode(bitmapData); 
    // Create a new FileReference: 
    var imageFile:FileReference = new FileReference(); 
    // Save the file: 
    imageFile.save(imageBytes, "myimage.png"); 
}