Skip to content

Instantly share code, notes, and snippets.

@xcuYao
Created July 8, 2018 03:12
Show Gist options
  • Save xcuYao/6ffa39fd06747360bbe3dea04a4c43e6 to your computer and use it in GitHub Desktop.
Save xcuYao/6ffa39fd06747360bbe3dea04a4c43e6 to your computer and use it in GitHub Desktop.
//Image 转 Base64
BufferedImage image = AliyunUtils.readImgFromOSS("jindi-api-data","api/6fd514de0e0983c8ffc451a200056001.png");
<!--BufferedImage image = ImageIO.read(new File(""));-->
ByteArrayOutputStream output = new ByteArrayOutputStream();
ImageIO.write(image, "png", output);
String base64 = Base64.getEncoder().encodeToString(output.toByteArray());
//base64 转 Image
byte[] imageData = Base64.getDecoder().decode(base64.getBytes());
BufferedImage image2 = ImageIO.read(new ByteArrayInputStream(imageData));
ImageIO.write(image2, "png", new File("/Users/yaoning/Desktop/a.png"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment