将Javaimage对象转换成PNG格式字节数组

文章作者 100test 发表时间 2007:03:26 17:53:37
来源 100Test.Com百考试题网


**

* 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:

*

* [email protected]

*

* 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.

相关文章


Java深入:认识classClass及其应用(2)
J2SE综合:JAVA实现把汉字转化成拼音(1)
Java深入:编写高级JScript应用代码
避免JavaEE项目评估中的常见错误
将Javaimage对象转换成PNG格式字节数组
JavaCard开发教程之接口
JAVA无线开发之定点库MathFP使用入门
JavaMail(JAVA邮件服务)API详解(1)
JavaMail(JAVA邮件服务)API详解(2)
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛