0

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

mabicha
  • 337
  • 2
  • 7
  • 16
  • 1
    Look at the mime-type of the part. MIME has headers so that you can figure out how to decode enclosures. – hobbs Sep 11 '12 at 18:36
  • @hobbs: Thanks for your reply! I think MimeType and ContentType are same. Actually, I had checked the ContentType and it shows as "image/png" type. – mabicha Sep 11 '12 at 18:52

1 Answers1

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.

Community
  • 1
  • 1
aroth
  • 54,026
  • 20
  • 135
  • 176
  • Thanks again aroth!! So just to be clear, that means that I could write the byte array to a file and name it as "image.png", and it would work(if writing to a file was allowed on GAE). Also, I think I can use pngj library mentioned in the link to get image in ARGB format, but I would need to convert other image formats(jpg,gif,etc.) to png as well. Do you know how I can do that on GAE ? – mabicha Sep 12 '12 at 19:31
  • 1
    From the API reference, it looks like you can use `ImageService.applyTransform(Transform transform, Image image, OutputSettings settings)` with `outputSettings` configured to specify your desired output format. Just use that with a `Transform` that doesn't actually modify the image, like `ImageServiceFactory.makeRotate(0)`. – aroth Sep 12 '12 at 23:49