Last active
June 9, 2021 08:36
-
-
Save mevsungur/ee0fc409666b0b0c0722e2637c33f057 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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