问题
I want to decode a base64 encoded image received over email on Google App Engine(GAE). When I extract the image from MimeMessage I get a base64DecoderStream object. I initially assumed that this decoded data is byte array in ARGB format, but that doesn't seem to be the case here. I verified this by comparing the decoded byte array with the one got from running "ImageIO.read(ImageFile).getRGB()" and they didn't match.
So I was wondering:-
1) Which image format data did I get after decoding the Image with base64 ?
2) How can I get the actual image PNG or JPG on GAE ?
3) Finally, is there a way to get the received email image in ARGB format on GAE ?
Any help is greatly appreciated... Thanks
回答1:
The Base64 encoded data is the image file itself, not the unpacked pixel data. It's the actual file that was attached to the message. So after decoding the Base64 data, in this particular case you had a binary PNG file.
To manipulate it as an image, you have several options:
- Pass the decoded
byte[]
directly toImagesServiceFactory.makeImage()
. - Write the decoded
byte[]
to file and callImagesServiceFactory.makeImageFromFilename()
. - Store the decoded
byte[]
into the database as aBlob
and then callImagesServiceFactory.makeImageFromBlob()
.
Once you've done that, unfortunately it doesn't look like there's a trivial way to get the ARGB data using Google's built-in API's. The solution discussed here may help: Extracting image pixel values in google appengine.
来源:https://stackoverflow.com/questions/12375806/decoding-base64-image-received-as-email-on-google-app-engine