Here you can find the source of encodeImageToPNGByteArray(BufferedImage image)
public static byte[] encodeImageToPNGByteArray(BufferedImage image)
//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; } }