My app downloads a Facebook user's jpeg profile picture and base64 encodes it. When decoding it, the resulting jpeg quality and size is significantly reduced. How do I avoid this?
Here is the way I'm downloading/encoding:
// 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()));
When I take the value of imageData and decode it, the image is way smaller than the one at the original download URL.