在Actionscript 3.0中将图像保存到本地磁盘

时间:2017-11-18 11:02:41

标签: actionscript-3 flash-builder flash-cs6 flash-cc

我在舞台上有一个矩形MovieClip(名为rect),我希望用户能够将该矩形MovieClip保存为他计算机上的“.png”图像,这就是我所做的:

//Convert my MovieClip to BitmapData
var bitmapData:BitmapData=new BitmapData(rect.width, rect.height);

//Create new ByteArray
var byteArray:ByteArray = new ByteArray();

//Encode my Bitmap to PNG
bitmapData.encode(new Rectangle(0,0,450,170), new flash.display.PNGEncoderOptions(), byteArray);

//saving the byteArray that holds the PNG as "myimage.png"
var fileReference:FileReference=new FileReference();
fileReference.save(byteArray, "myimage.png"); 

当我运行代码时,它会提示窗口保存对话框,当我保存图像时,我得到一个名为“myimage.png”的空白“.png”图像,其大小为450x170,我已指定。有什么想法解决这个问题吗?

0 个答案:

没有答案
相关问题