我的应用程序下载 Facebook 用户的 jpeg 个人资料图片,并对其进行 base64 编码。解码时,生成的 jpeg 质量和大小会显着降低。我该如何避免这种情况?
这是我下载/编码的方式:
// Download the profile picture.
BufferedImage image = ImageIO.read(new URL("http://facebook-profile-pic"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(image, "jpeg", bos);
// Base64 encode it.
String imageData = new String(Base64.getEncoder().encode(bos.toByteArray()));
当我获取 imageData 的值并对其进行解码时,图像比原始下载 URL 中的图像小得多。