Java BufferedImage Encode encodeImageToPNGByteArray(BufferedImage image)

Here you can find the source of encodeImageToPNGByteArray(BufferedImage image)

Description

encode Image To PNG Byte Array

License

Open Source License

Declaration

public static byte[] encodeImageToPNGByteArray(BufferedImage image) 

Method Source Code

//package com.java2s;
/*/*from   w ww .  j  a  v a 2  s.  c  o  m*/
 * $Id: PixelUtil.java,v 1.3 2007/01/29 09:08:46 eiki Exp $ Created on May 29,
 * 2006
 * 
 * Copyright (C) 2006 Idega Software hf. All Rights Reserved.
 * 
 * This software is the proprietary information of Idega hf. Use is subject to
 * license terms.
 */

import java.awt.image.BufferedImage;

import java.io.ByteArrayOutputStream;

import javax.imageio.ImageIO;

public class Main {
    public static byte[] encodeImageToPNGByteArray(BufferedImage image) {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ImageIO.write(image, "png", bos);
            return bos.toByteArray();
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
        return null;
    }
}

Related

  1. encodeAndWriteJPEGFile(File file, BufferedImage image, float quality)
  2. encodeBufferedImageAsJPEG(BufferedImage bi)
  3. encodeImage(BufferedImage image)
  4. encodeImage(BufferedImage image)
  5. encodeImageToBase64(BufferedImage image)
  6. encodeJPEG(BufferedImage image)
  7. encodePNG(BufferedImage image, String pathAndFileName)
  8. encodeToImgElement(BufferedImage image, String formatName)