I'm encoding the BitmapData using this method: http://www.websector.de/blog/2009/06/21/speed-up-jpeg-encoding-using-alchemy/
Code example:
var loader:CLibInit = new CLibInit;
as3_jpeg_wrapper = loader.init();
var baSource: ByteArray = bitmapData.clone().getPixels( new Rectangle( 0, 0, WIDTH, HEIGHT) );
var baAlchmey: ByteArray = as3_jpeg_wrapper.write_jpeg_file(baSource, WIDTH, HEIGHT, 3, 2, quality);
After encoding i need to convert resulting byteArray back to BitmapData. I'm using setPixels()
method.
For example:
baAlchemy.position = 0;
var bd:BitmapData = new BitmapData(width, height);
bd.setPixels(rect, baAlchemy);
And i get "Error #2030: End of file was encountered?".
Can anybody help me?
It looks like you are trying to pass the bytes of a compressed JPEG to setPixels()
.
However, according to the documentation setPixels()
, it the second argument to be:
A ByteArray object that consists of 32-bit unmultiplied pixel values to be used in the rectangular region
Or, in other words, an uncompressed image. You will first have to decompress your image, before you can render it into a BitmapData