解码在 Google App Engine 上作为电子邮件收到的 base64 图像 [英] Decoding base64 image received as email on Google App Engine

查看:44
本文介绍了解码在 Google App Engine 上作为电子邮件收到的 base64 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解码通过电子邮件在 Google App Engine (GAE) 上收到的 base64 编码图像.当我从 MimeMessage 中提取图像时,我得到一个 base64DecoderStream 对象.我最初假设此解码数据是 ARGB 格式的字节数组,但这里似乎并非如此.我通过将解码的字节数组与运行ImageIO.read(ImageFile).getRGB()"的数组进行比较来验证这一点,但它们不匹配.

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.

所以我想知道:-

1) 使用 base64 解码图像后我得到了哪种图像格式数据?

1) Which image format data did I get after decoding the Image with base64 ?

2) 如何在 GAE 上获取实际图像 PNG 或 JPG?

2) How can I get the actual image PNG or JPG on GAE ?

3) 最后,有没有办法在 GAE 上以 ARGB 格式获取收到的电子邮件图像?

3) Finally, is there a way to get the received email image in ARGB format on GAE ?

非常感谢任何帮助...谢谢

Any help is greatly appreciated... Thanks

推荐答案

Base64 编码数据是图像文件本身,而不是解压后的像素数据.这是附加到消息的实际文件.所以在解码 Base64 数据之后,在这种特殊情况下,您有一个二进制 PNG 文件.

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. 将解码后的byte[]直接传递给ImagesServiceFactory.makeImage().
  2. 将解码后的byte[]写入文件并调用ImagesServiceFactory.makeImageFromFilename().
  3. 将解码后的byte[]作为Blob存储到数据库中,然后调用ImagesServiceFactory.makeImageFromBlob().
  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().

完成此操作后,不幸的是,使用 Google 的内置 API 获取 ARGB 数据的方法似乎并不简单.此处讨论的解决方案可能会有所帮助:在 google appengine 中提取图像像素值.

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.

这篇关于解码在 Google App Engine 上作为电子邮件收到的 base64 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆