本文介绍了JPEG 编码器超慢,如何优化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Flash 构建器中使用 actionscript 3.0 构建应用程序.这是一个后续问题这个问题.

I'm building an App with actionscript 3.0 in my Flash builder. This is a followup question this question.

我需要将 bytearray 上传到我的服务器,但是我用来将 bitmapdata 转换为 ByteArray 的函数非常慢,太慢了,它冻结了我的移动设备.我的代码如下:

I need to upload the bytearray to my server, but the function i use to convert the bitmapdata to a ByteArray is super slow, So slow it freezes up my mobile device. my code is as follows:

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?有没有更好的办法?提前致谢!

Is there a different way to convert it to a byteArray? is there a better way? thanks in advanced!

~我的

推荐答案

使用 BitmapData.encode(),在移动设备上速度快了几个数量级 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#encode%28%29

Use BitmapData.encode(), it's faster by orders of magnitude on mobile http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#encode%28%29

这篇关于JPEG 编码器超慢,如何优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:56