Has anyone succesfully used this encoder in flashbuilder 4.5.1?
I’m getting this error??? usually on loading up a second pic. any help is appreciated.
RangeError: Error #1506: The specified range is invalid.
at cmodule.aircall::FSM_imalloc$/start()
at cmodule.aircall::FSM_pubrealloc/work()
at cmodule.aircall::CRunner/work()
at Function/<anonymous>()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
my code is as follows:
private var im:img;
private var jpgStream:ByteArray;
private var jpeglib:Object;
private var jpeginit:CLibInit = new CLibInit(); // get library
public function save_image(_im:img, pg:Number):void
{
var bm:BitmapData = Bitmap(_im.getChildAt(0)).bitmapData;
im = _im;
var imgData:ByteArray = bm.getPixels(bm.rect);
jpgStream = new ByteArray();
imgData.position = 0;
trace(bm == null);
var jpegQuality:Number = 40;
if (!jpeglib) {
jpeglib=jpeginit.init();
}
jpeglib.encodeAsync(encodeComplete, imgData, jpgStream, bm.width, bm.height, jpegQuality);
}
private function encodeComplete(e:Event):void {
trace("Encoding complete");
file = File.documentsDirectory.resolvePath("Pic-A-Note/" + albumName + "/object_layer_" + im.name + ".pn");
fs.open(file, FileMode.WRITE);
fs.writeBytes(jpgStream,0);
fs.close();
}
The problem is that you are initializing the CLibInit twice. I’ve created a custom class to handle encode of jpg’s transparently using jpegencoder.swc, like you do with the native class.
Check how the constructor deal with the static CLib. This way you can start as many JPGAlchemyEncoder’s as you want but the CLib will be initialized only once, solving your problem.