Flex / AS3: The best way to encode JPEG

Recently in my diploma I need to encode jpeg file on client, after some research I found library created using Alchemy project( from C/C++ language).It allows you to encode jpeg both synchronous and asynchronous.

After downloading library and including it in your project, you should do:

1. Init library

private var init1:CLibInit;
private var lib : Object;

private function initAlchemy():void
{
init1 = new CLibInit();
lib = init1.init();
}
2.Prepare your image
private var bd:BitmapData ; //your image here
public var byteArr:ByteArray = bd.getPixels( bd.rect );
3.1 Encode your image synchronous
var ba:ByteArray = bd.getPixels( bd.rect );
ba.position = 0;
byteArr = new ByteArray();

//result will be in byteArr
lib.encode(ba, byteArr, bd.width, bd.height, 100);
fileRef.save(byteArr,"NewFileName1.jpg");
encode( src:BimapData, image_data:ByteArrat, imageWidth:uint, imageHeight:uint, quality:int );

Parameters:

src:BitmapData - bitmapData to be encoded. cannot be null !
image_data:ByteArray - buffer where jpeg image will be written to. cannot be null !
imageWidth:int - 'src' image width
imageHeight:int - 'src' image height
quality:int - jpeg quality (1-100)


3.1 Encode your image asynchronous
lib.encodeAsync( finish, bd, ba,bd.width, bd.height, 100, tuning:int );

encodeAsync( callback:Function, src:BimapData, image_data:ByteArrat, imageWidth:uint, imageHeight:uint, quality:int, tuning:int );

Parameters:

callback:Function - callback function to be called when compression is finished. function is invoked with out parameter, image_data byteArray (the same passed as a image_data parameter
src:BitmapData - see synchronous method
image_data:ByteArray - see synchronous method
imageWidth:int - see synchronous method
imageHeight:int - see synchronous method
quality:int - see synchronous method
tuning:int - this is most important parameter, it defines 'how often' method is going to interrupted and control flow returned to other parts of application. it should be interpreted, rather as a 'number of scanlines to be compressed in a single timeslice'


References:
Flex Tutorial - An Asynchronous JPEG Encoder 
Alchemy - asynchronous jpeg encoding #2 
Alchemy - asynchronous jpeg encoding 
First I tried  bytearray.org

Sursa
2011-03-06 15:35:00



Comenteaza





Ultimele 25 posturi adăugate

11:51:22Cafeneaua Literară: Spiritul Creator al Modernismului —» Biblioteca de Arte 'Tudor Arghezi'
08:40:56The Governor Fume Blanc 2023: Grand Gold —» Fine Wine
12:33:00Fantome —» Andrei LANGA. Blogul personal
01:17:34Fără Titlu —» Путепроводные Заметки
17:12:08Fără Titlu —» Путепроводные Заметки
16:02:57Fără Titlu —» Путепроводные Заметки
14:57:42Fără Titlu —» Путепроводные Заметки
13:29:01Fără Titlu —» Путепроводные Заметки
12:12:00Pământ —» Andrei LANGA. Blogul personal
12:12:00Pământ —» Andrei LANGA. Blogul personal
04:32:00POEME PRIN ANI —» Leo Butnaru
03:46:13Fără Titlu —» Путепроводные Заметки
01:54:22Fără Titlu —» Путепроводные Заметки
01:46:39Fără Titlu —» Путепроводные Заметки
14:52:02Fără Titlu —» Путепроводные Заметки
04:37:00DIN POEZIA LUMII —» Leo Butnaru
00:53:00do you remember being scared? —» turn up the silence
21:41:43Fără Titlu —» Путепроводные Заметки
18:14:39Fără Titlu —» Путепроводные Заметки
14:30:40Fără Titlu —» Путепроводные Заметки
11:33:16Interpretări Teatrale ale lui Eminescu: Luceafărul —» Biblioteca de Arte 'Tudor Arghezi'
01:04:11Fără Titlu —» Путепроводные Заметки
23:45:50Fără Titlu —» Путепроводные Заметки
22:36:52Fără Titlu —» Путепроводные Заметки
21:23:03Fără Titlu —» Путепроводные Заметки