기본 이미지를 임베드 된 이미지로 그대로두고 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");
}