views:

267

answers:

2

I'm currently using the JPGEncoder from the AS3 core lib to encode a bitmap to JPEG

 var enc:JPGEncoder = new JPGEncoder(90);
 var jpg:ByteArray = enc.encode(bitmap);

Because the bitmap is rather large (3000 x 2000) the encoding takes a long while (about 20 seconds), causing the application to seemingly freeze while encoding. To solve this, I need either:

  • An asynchronous encoder so I can keep updating the screen (with a progress bar or something) while encoding
  • An alternative encoder which is simply faster

Is either possible, and how can I do it?

+1  A: 

Setting up the encoder to be asynchronous would likely be your best bet.

Here are two examples from Adobe

This example is with actionscript/flex, but its the same idea.

Jason W
And how do I do that? :) The JPGEncoder has only one method, "encode".
Bart van Heukelom
Found one, see my answer.
Bart van Heukelom
Beat me to it :) I've added a few different examples as well for reference.
Jason W
+2  A: 

I found an asynchronous encoder: http://www.switchonthecode.com/tutorials/flex-tutorial-an-asynchronous-jpeg-encoder

Bart van Heukelom