3
votes

I have an embedded image asset (with a scale9 grid), and I'm trying to get the bitmapdata when it's resized, but I can't seem to do this without adding it to the display list.

I try this:

spriteAsset.setActualSize(w,h);
spriteAsset.width = w;
bmd.draw(spriteAsset);

But when I then draw out the bitmapdata with graphics.beginBitmapFill(), I just get the original un-stretched image.

Any pointers? Or do I need to take 9 separate BitmapData images and make 9 separate bitmap fills?

Cheers, -Josh

2
Have you tried putting your spriteAsset inside another Sprite (that is not scaled) and then drawing the parent Sprite?danjp
Also, I should note - setActualSize() does not immediately resize the object, it flags it for update in a later call by the framework to updateDisplayList()quoo

2 Answers

2
votes

My experience taking BitmapData.draw() snapshots of scale9 assets has been that the scale9 is discarded, even if the asset has been added to the display list. This is a bug as far as I'm concerned, I don't know if it's been reported.

Aside from the scale9 disappointment, don't forget that BitmapData.draw can take a matrix parameter. By default it's null, meaning the identity matrix (no scale, rotation, etc). To take a snapshot of a transformed asset, you need to provide its transformation matrix...

bmd.draw(spriteAsset, spriteAsset.transform.matrix)

(Haven't double checked this stuff sorry, so ymmv.)

0
votes

Danjp's solution is good, but if you want to resize the bitmap data itself, try using a scale matrix, ie:

var scaledBitmapData:BitmapData = new BitmapData(newWidth, newHeight);
var scaleMatrix:Matrix = new Matrix();
scaleMatrix.scale(scaleFactor, scaleFactor);

scaledBitmapData.draw(bitmap, scaleMatrix);