Flex/actionscript 快照 [英] Flex/actionscript snapshot

查看:25
本文介绍了Flex/actionscript 快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

在上面的代码中保存文件后,当我尝试打开它,我收到这不是有效的位图文件".我尝试了 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)

data 字段不需要 BitmapData 像素数据 (bmp.getPixels),它需要在给定的 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);

一旦你必须自己编码,你应该取消第二个 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/actionscript 快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆