1

2 つの jpeg を使用してフラッシュで透過ビットマップを生成します。1 つは BitmapDataChannel を読み取るための白黒で、もう 1 つは実際の画像です。

これは私のコードです:

private var sourceBitmap:BitmapData;
private var alphaBitmap:BitmapData;
private var outputBitmap:BitmapData;
private var bitmap:Bitmap;

//Updated Code:
private var sourceByteArray:ByteArray = new ByteArray(), outputByteArray:ByteArray = new ByteArray(), alphaByteArray:ByteArray = new ByteArray();
private var jpegencoderoptions = new JPEGEncoderOptions(0);

//get image from library
this.sourceBitmap = new imageFromLibrary();
//Updated: encode sourceBitmap
this.sourceBitmap.encode(this.sourceBitmap.rect, jpegencoderoptions, this.sourceByteArray);
//create new bitmapData with dimensions of sourcimage.      
this.outputBitmap = new BitmapData(this.sourceBitmap.width, this.sourceBitmap.height, true, 0x00000000);
//Updated: encode outputBitmap
this.outputBitmap.encode(this.outputBitmap.rect, jpegencoderoptions, this.outputByteArray);

this.outputBitmap.lock();

//copy the pixels from source to output
this.outputBitmap.copyPixels(this.sourceBitmap, this.sourceBitmap.rect, new Point());
//free memory and dispose source
this.sourceBitmap.dispose();
//Updated: clear sourceByteArray
this.sourceByteArray.clear();

//get alphamap from library         
this.alphaBitmap = new alphamapFromLibrary();
//Updated: encode alphaBitmap 
this.alphaBitmap.encode(this.alphaBitmap.rect, jpegencoderoptions, this.alphaByteArray);

//copy the channel from alpha to output
this.outputBitmap.copyChannel(this.alphaBitmap, this.alphaBitmap.rect, new Point(), BitmapDataChannel.RED, BitmapDataChannel.ALPHA);

//free memory and dispose alpha
this.alphaBitmap.dispose();
//Updated: clear alphaByteArray
this.alphaByteArray.clear();

this.bitmap = new Bitmap(this.outputBitmap);

コードはうまく機能し、透明な画像が生成されます。しかし、今の私の問題は、RAM の負荷が高いことです。古いスマートフォンでは、RAM を超えてゲームが終了します。

主な問題は次のとおりです。sourceBitmap をロードすると、RAM が必要になります。その後、新しい BitmapData "outputBitmap" を生成します。これにより、RAM に同じ次元の BitmapData が 2 倍あります。

私の質問は次のとおりです。いくつかの手順をスキップして sourceBitmap をロードし、transparent を true に設定し、ソースをロードする代わりにチャネルをこのソースにコピーし、出力を作成することはできますか?

編集:

BitmapData.encode()BitmapDatas を JPEG にエンコードするようにコードを更新しました。ただし、メモリ使用量が常に変化するとは限りません。エンコード後にメモリ使用量が増える場合もあれば、減る場合もあれば、変わらない場合もあります。

4

0 に答える 0