Java Utililty Methods BufferedImage to PNG

List of utility methods to do BufferedImage to PNG

Description

The list of methods to do BufferedImage to PNG are organized into topic(s).

Method

StringimageAsBase64Png(Component c)
image As Base Png
if (c.getWidth() <= 0 || c.getHeight() <= 0) {
    return "";
BufferedImage img = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_RGB);
c.paint(img.getGraphics());
ByteArrayOutputStream buf = new ByteArrayOutputStream();
try {
    ImageIO.write(img, "png", buf);
...
byte[]imageToPNG(BufferedImage image)
Converts an image to a PNG stored in a byte array.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
    BufferedImage buffer = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
    buffer.createGraphics().drawImage(image, 0, 0, null);
    ImageIO.write(buffer, "PNG", baos);
    baos.close();
} catch (IOException e) {
...
voidimageToPngFile(BufferedImage image, File pngFile)
image To Png File
try {
    ImageIO.write(image, "png", pngFile);
} catch (IOException e) {
    throw new RuntimeException("Failed to write image to file: " + pngFile, e);
voidimage(BufferedImage image)
image
try {
    ImageIO.write(image, "png", new File("debug123.png"));
} catch (Exception _) {
booleanbufferedImageToFile(BufferedImage src, String path)
buffered Image To File
try {
    File outputFile = new File(path);
    ImageIO.write(src, "png", outputFile);
    return true;
} catch (IOException e) {
    e.printStackTrace();
return false;
...