views:

61

answers:

2

Hi guys,

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

A: 

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);
quoo
Using the matrix does scale it, but the scale9 grid is ignored :(
Sophistifunk
Oh oops, I'm sorry, I completely overlooked the scale 9 part.
quoo
+2  A: 

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.)

aaaidan
Thought as much. I was hoping there was a stupid flag I'd not noticed, like maintainAspectRation on Image :)
Sophistifunk