** * PngEncoder takes a Java Image object and creates a byte string which can be saved as a PNG file。 * The Image is presumed to use the DirectColorModel。
* * Thanks to Jay Denny at KeyPoint Software * http://www。keypoint。com/ * who let me develop this code on company time。 * * You may contact me with (probably very-much-needed) improvements, * comments, and bug fixes at: * * david@catcode。
com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2。
1 of the License, or (at your option) any later version。 *
* This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE。
See the GNU * Lesser General Public License for more details。 *
* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc。
, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * A copy of the GNU LGPL may be found at * http://www。gnu。org/copyleft/lesser。
html, * * @author J。 David Eisenberg * @version 1。4, 31 March 2000 */ import java。awt。*; import java。awt。image。*; import java。
util。*; import java。util。zip。*; import java。io。*; public class PngEncoder extends Object { /** Constant specifying that alpha channel should be encoded。
*/ public static final boolean ENCODE_ALPHA=true; /** Constant specifying that alpha channel should not be encoded。
*/ public static final boolean NO_ALPHA=false; /** Constants for filters */ public static final int FILTER_NONE = 0; public static final int FILTER_SUB = 1; public static final int FILTER_UP = 2; public static final int FILTER_LAST = 2; protected byte[] pngBytes; protected byte[] priorRow; protected byte[] leftBytes; protected Image image; protected int width, height; protected int bytePos, maxPos; protected int hdrPos, dataPos, endPos; protected CRC32 crc = new CRC32(); protected long crcValue; protected boolean encodeAlpha; protected int filter; protected int bytesPERPixel; protected int compressionLevel;。
全部