public final static void encode(Image image, OutputStream os) throws IOException {
		CRC32 crc = new CRC32();

		int width = image.width;
		int height = image.height;

		write(os, null, PNGHelper.ID);

		write(os, crc, PNGHelper.IHDR);
		write(os, crc, width);
		write(os, crc, height);
		write(os, crc, PNGHelper.HEAD);

		writeCRC(os, crc);

		ByteArrayOutputStream compressed = new ByteArrayOutputStream(defaultInitDataSize);
		BufferedOutputStream cbos = new BufferedOutputStream(
				new DeflaterOutputStream(compressed, new Deflater(9)), defaultBufferSize);
		int pixel;
		for (int y = 0; y < height; y++) {
			cbos.write(0);
			for (int x=0;x<width;x++) {
				pixel = image.getPixel(x,y);
				cbos.write((byte)((pixel >> 16) & 0xFF));//R
				cbos.write((byte)((pixel >> 8) & 0xFF));//G
				cbos.write((byte)(pixel & 0xFF));//B
				cbos.write((byte)((pixel >> 24) & 0xFF));//A
			}
		}
		cbos.close();
		write(os, null, compressed.size());

		write(os, crc, PNGHelper.IDAT);
		write(os, crc, compressed.toByteArray());
		writeCRC(os, crc);
		write(os, null, 0);

		write(os, crc, PNGHelper.IEND);
		writeCRC(os, crc);

		os.close();
	}