0

500x500のソースビットマップからx=100、y=100の200x200サイズのビットマップを「CUTTINGOUT」で探しています。これが私のコードです:

  var tempData:BitmapData 
  var tempBitmap:Bitmap ;
tempData = new BitmapData(500, 500,false, 0xffffff);

tempBitmap  = new Bitmap(tempData);

tempData.draw(original,null, null, null, new Rectangle(100, 100, 200, 200),true);

うまく機能しますが、

問題は、(0,0)から(100 + 200、100 + 200)に描画されることです。ただし、(0,0)から(100,100)にクリップします。したがって、他の部分が真っ白であっても、サイズは200x200より大きくなります。

描画は100,100から300,300から開始する必要があります。このビットマップを配置するムービークリップのサイズは200x200である必要があります。真っ白な領域は表示されません。ただし、x = 100、y=100からx=300、y=300までのソースビットマップのコンテンツのみ

それでも説明がわからない場合は、遠慮なくコメントしてください。

ありがとう

4

1 に答える 1

4

BitmapDataあるインスタンスから別のインスタンスにいくつかのピクセルをコピーする場合は、はるかに高速で操作copyPixels()の混乱が少ないため、使用してください。

関連する議論を強調します:

  1. sourceBitmapData:BitmapData-BitmapDataピクセルを取得するインスタンス。
  2. sourceRect:Rectangle-Rectangleソースのどの部分が必要かを指定します。
  3. destPoint:Point-Point宛先のどこにソースが描画されるかを表す。

だからあなたがしたいのはこれです:

// Define BitmapData.
var sourceBitmapData:BitmapData = new BitmapData(500, 500, false, 0xFF0000);
var destinationBitmapData:BitmapData = new BitmapData(200, 200, false, 0xFFFFFF);

// Add viewable Bitmap representation.
var view:Bitmap = new Bitmap(destinationBitmapData);
addChild(view);


// Define where pixels will be taken from off the source.
var clipRectangle:Rectangle = new Rectangle(100, 100, 200, 200);

// Define where the pixels will be drawn at on the destination.
var destPoint:Point = new Point(); // Didn't catch where you wanted this to be drawn at - simply provide your own x, y here.

// Copy some pixels from sourceBitmapData across to destinationBitmapData.
destinationBitmapData.copyPixels(sourceBitmapData, clipRectangle, destPoint);

不明な点がありましたらお知らせください。

于 2012-05-23T06:29:54.723 に答える