JPEG编码器超级慢,如何优化呢?

我正在使用ActionScript构build器中的ActionScript 3.0构build应用程序。 这是这个问题的后续问题 。

我需要上传bytearray到我的服务器,但我用来将bitmapdata转换为ByteArray的function是超级慢,所以慢它冻结了我的移动设备。 我的代码如下:

var jpgenc:JPEGEncoder = new JPEGEncoder(50); trace('encode'); //encode the bitmapdata object and keep the encoded ByteArray var imgByteArray:ByteArray = jpgenc.encode(bitmap); temp2 = File.applicationStorageDirectory.resolvePath("snapshot.jpg"); var fs:FileStream = new FileStream(); trace('fs'); try{ //open file in write mode fs.open(temp2,FileMode.WRITE); //write bytes from the byte array fs.writeBytes(imgByteArray); //close the file fs.close(); }catch(e:Error){ 

有没有不同的方式将其转换为byteArray? 有没有更好的办法? 先谢谢了!

〜MYY

尝试使用stream血图书馆: http : //www.blooddy.by 。 但我没有在移动设备上进行testing。 评论你是否会成功。

使用BitmapData.encode(),在手机上它的速度要快几个数量级http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#encode%28%29

您应该尝试find能够asynchronous编码的JPEG编码器。 这样的方式应用程序仍然可以在图像被压缩时使用。 我还没有尝试过任何一个库,但是这个看起来很有希望:

http://segfaultlabs.com/devlogs/alchemy-asynchronous-jpeg-encoding-2

它使用Alchemy ,它应该比as3corelib中的JPEGEncoder更快(我猜这是你现在使用的那个)。

一个本地JPEG编码器是理想的,asynchronous将是好的,但可能仍然缓慢(只是不阻止)。 另外一个select:

 var pixels:ByteArray = bitmapData.getPixels(bitmapData.rect); pixels.compress(); 

我不太清楚本机的performance,而且performance绝对取决于你有什么样的图像。

伊利亚的答案对我来说是什么。 我下载了这个库,里面有一个如何使用它的例子。 我一直在努力让flashbuilder中的CameraUI拍照,编码/压缩,然后通过Web服务发送给我的服务器(数据是以压缩字节数组的forms发送的)。 我做到了这一点:

by.blooddy.crypto.image.JPEGEncoder.encode(bmp,30);

其中bmp是我的位图数据。 编码花了3秒钟,很容易适应我的控制stream同步。 我尝试了asynchronous方法,但他们最终花了很长时间,很难跟踪像用户从单元服务移动到WiFi或从塔到塔,而上传正在进行的东西。

如果您需要更多的细节,请点评

Interesting Posts