Skip to content

Instantly share code, notes, and snippets.

@mevsungur
Last active June 9, 2021 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mevsungur/ee0fc409666b0b0c0722e2637c33f057 to your computer and use it in GitHub Desktop.
Save mevsungur/ee0fc409666b0b0c0722e2637c33f057 to your computer and use it in GitHub Desktop.
//Buffered Image nesnesini Base64 encoded stringe dönüştürmek için
public static String bufferedImgToBase64String(final BufferedImage img, final String formatName) {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ImageIO.write(img, formatName, Base64.getEncoder().wrap(os));
return os.toString(StandardCharsets.ISO_8859_1.name());
} catch (final IOException ioe) {
throw new UncheckedIOException(ioe);
}
}
//Buffered Image nesnesini byte dizisine dönüştürmek için.
public static byte[] bufferedImgToByteArray(final BufferedImage img, final String formatName) {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ImageIO.write(img, formatName, os);
return os.toByteArray();
} catch (final IOException ioe) {
throw new UncheckedIOException(ioe);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment