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');
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.
To extend Amarghosh’s answer, look to the constructor of ImageSnapshot
The
datafield isn’t expecting BitmapData pixel data (bmp.getPixels), it’s expecting data encoded in the givencontentType. So you could do:Once you have to encode it yourself anyway, you should probably do away with the second
ImageSnapshotreference and use: