的Flex /动作快照 [英] Flex/actionscript snapshot
问题描述
var bmd:BitmapData = ImageSnapshot.captureBitmapData(someSprite);
trace("bmd size "+getSize(bmd));
var bounds:Rectangle = new Rectangle(0, 0, bmd.width, bmd.height);
var snapshot:ImageSnapshot = new ImageSnapshot(0,0,bmd.getPixels(bounds));
//var snapshot:ImageSnapshot = ImageSnapshot.captureImage(someSprite);
var file:FileReference = new FileReference();
file.save(snapshot.data,'abc.png');
在保存文件时,经过上面的code 我尝试打开它,我得到这不是一个有效的位图文件。我曾尝试2-3不同的观众。
In the above code after saving the file, when I try to open it, I get "This is not a valid bitmap file". I have tried 2-3 different viewers.
推荐答案
要延长Amarghosh的回答,期待将ImageSnapshot的构造
To extend Amarghosh's answer, look to the constructor of ImageSnapshot
ImageSnapshot(width:int, height:int, data:ByteArray, contentType:String)
在数据
字段不期望的BitmapData像素数据(bmp.getPixels <$ C C $>),该公司预计,数据连接codeD在给定的的contentType
。所以,你可以这样做:
The data
field isn't expecting BitmapData pixel data (bmp.getPixels
), it's expecting data encoded in the given contentType
. So you could do:
var encoder:PNGEncoder = new PNGEncoder();
var bytes:ByteArray = encoder.encode(bmp);
new ImageSnapshot(width, height, bytes, encoder.contentType);
在你要连接code你自己无论如何,你应该废除第二将ImageSnapshot
参考和使用:
Once you have to encode it yourself anyway, you should probably do away with the second ImageSnapshot
reference and use:
new FileReference().save(bytes, "abc.png");
这篇关于的Flex /动作快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!