0
votes

Im using the bulkloader library on AIR to download an image, then using the AS3corelib im trying to save the file locally using:

var byteArray:ByteArray = jpgEncoder.encode( loader.getContent("IMG_0004.JPG") );
stream.writeBytes(byteArray);
stream.close();

But im getting this error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Bitmap@8349a81 to flash.utils.ByteArray.

I have no idea how to solve this.

2

2 Answers

3
votes

The encode function wants a BitmapData object, but you're giving it a Bitmap.

So you should just be able to do this:

var byteArray:ByteArray = jpgEncoder.encode( Bitmap(loader.getContent("IMG_0004.JPG")).bitmapData );
1
votes

DomingoSL, so your original prob was solved and now your problem is jpeg encoding. yes the jpeg encoder in the standard library is very slow. its the slowest encoder you could ever use. read it up on: http://www.bytearray.org/?p=775. Hint: read all the comments and youll get your answer to silent saves.