JPEG encoder super slow, how to Optimize it?

无人久伴 提交于 2019-12-01 21:06:13

Try to use blooddy library: http://www.blooddy.by . But i didn't test it on mobile devices. Comment if you will have success.

You should try to find a JPEG encoder that is capable of encoding asynchronously. That way the app can still be used while the image is being compressed. I haven't tried any of the libraries, but this one looks promising:

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

It uses Alchemy, which should make it faster than the JPEGEncoder from as3corelib (which I guess is the one you're using at the moment.)

A native JPEG encoder is ideal, asynchronous would be good, but possibly still slow (just not blocking). Another option:

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

I'm not sure of native performance, and performance definitely depends on what kind of images you have.

The answer from Ilya was what did it for me. I downloaded the library and there is an example of how to use it inside. I have been working on getting the CameraUI in flashbuilder to take a picture, encode / compress it, then send it over via a web service to my server (the data was sent as a compressed byte array). I did this:

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

Where bmp is my bitmap data. The encode took under 3 seconds and was easily able to fit into my flow of control synchronously. I tried async methods but they ultimately took a really long time and were difficult to track for things like when a user moved from cell service to wifi or from tower to tower while an upload was going on.

Comment here if you need more details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!