开发者

Is it possible to resize a SpriteAsset without adding it to the display list?

开发者 https://www.devze.com 2022-12-25 09:01 出处:网络
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 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;
b开发者_运维百科md.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


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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号