You all may seen the brilliant Flash 9 class for JPEG Encoding made by Kyle. It is greatly optimized using linked lists and doesn’t require Flash 10 for pretty fast encoding. Sure Alchemy version is the fastest but once again – we are talking about Flash 9. I’ve rebuild it’s class a little to implement asynchronous encoding and add merging method as in my previous example here. In the example below you can choose desired result image size and generate JPEG file. It generates N number of BitmapData objects each one is maximum size of 2800 pix. And then encode them asynchronous in to single JPEG file. This example requires Flash 10 cause it gives you an ability to save result image to local drive without server. None of F10 features used for encoding.
Download modified JPEG encoder class
Simple usage example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | var bmp1:BitmapData = new BitmapData(2800, 2800, false, 0xFF0000); var bmp2:BitmapData = new BitmapData(2800, 2800, false, 0x00FF00); var bmp3:BitmapData = new BitmapData(2800, 2800, false, 0x0000FF); var bmp4:BitmapData = new BitmapData(2800, 2800, false, 0xFFFF00); var bmp5:BitmapData = new BitmapData(2800, 2800, false, 0xFF00FF); var bmp6:BitmapData = new BitmapData(2800, 2800, false, 0x00FFFF); je = new JPGEncoder(90); je.addEventListener(Event.COMPLETE, onEncoded); je.addEventListener(ProgressEvent.PROGRESS, onEncodeProgress); // je.blocksPerIteration = 196; je.encodeMultiToOne( [ [bmp1, bmp2, bmp3], [bmp4, bmp5, bmp6] ]); function onEncoded(e:Event = null):void { trace('JPEG ENCODED'); } function onEncodeProgress(e:ProgressEvent):void { trace('Encoding JPEG: ' + String( Math.round(e.bytesLoaded / e.bytesTotal * 100) ) + '%'); } function saveImg(e:MouseEvent = null):void { // here is our JPEG file ByteArray data // je.encodedImageData } |



Sweet! Exactly what I need.
Wow – Can’t wait to use this. Amazing work – thanks for sharing.
Brillant!
It would have needed it the last month XD
Thanx
Awesome work! I was hoping someone would make encoding asynchronous
Nobody likes to see Flash Player freeze their browser when trying to encode an image.
I have done a quick and dirty comparison with this version against the one at http://code.google.com/p/in-spirit/source/browse/trunk/projects/FlickrMosaic/src/ru/inspirit/utils/JPGEncoder.as, and it does not seem any faster at all.
Can you post any more accurate results?
@Guti I wont be faster using async encoding. Cause the speed is identical there. But this class is a lot faster in not-async encoding thats why I decided to use it.