Decoding base64 image received as email on Google App Engine

流过昼夜 提交于 2019-12-25 03:01:58

问题


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:

  1. Pass the decoded byte[] directly to ImagesServiceFactory.makeImage().
  2. Write the decoded byte[] to file and call ImagesServiceFactory.makeImageFromFilename().
  3. Store the decoded byte[] into the database as a Blob and then call ImagesServiceFactory.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!