Copy link to clipboard
Copied
Hi,
using AS3, for an AIR application, I have a BitmapData object (obtained from webcam shot). I need to compress the image with JPEGEncoder and save it in a SQLLIte database (string?).
And then I need to re-build the BitmapData object using the data stored in the database.
It's importante the passage of the jpeg compression!
Has someone an idea about how to implement this?
THANK YOU IN ADVACE!
Copy link to clipboard
Copied
the jpegencoder constructor accepts a quality parameter (and you can use the jpegencoderoptions class) to compress the file.
here's more info: Adobe Flash Platform * Compressing bitmap data
Copy link to clipboard
Copied
Hi, thank you for your reply.
I actually know how to compress an image using JPEGEncoder. What I don't know is how to rebuild the BitmapData starting from the ByteArray obtained by the JPEGEncoder.
Note that I cannot used the UrlLoader, because my jpeg is not stored in the filesystem but in the database (encoding the ByteArray as a String).
Copy link to clipboard
Copied
then you should probably not use the jpegencoder.
create your own array of pixels that you save and load. you can compress your data by collapsing same colored adjacent pixels. in my experience that cuts storage space significantly though it obviously depends on the bitmap.
Copy link to clipboard
Copied
Encode the ByteArray from the JPEG encoder to a Base64 string and store that. You can then easily rebuild the JPEG from the string... Just Google Base64 to Jpeg AS3 and you'll find all you need.
Copy link to clipboard
Copied
HI dmennenoh,
but after converting the string to byteArray (which represents the Jpeg image), how to convert it in a BitmapData object.
Please, if you could sugest some code, because I've googled a lot, but without finding what I need.
NOTE: I need a synchronous way to trasform the bytearray jpeg to BitmapData.
Thank you very much!
Copy link to clipboard
Copied
Hmm, I seem to find info right away about this... anyway, look at the setPixels method of BitmapData - should be what you need.