⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gifencoder.html

📁 java对GIF的编解码工具,有完整的说明和例子
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.4.2_04) on Wed Dec 15 18:51:45 EET 2004 -->
<TITLE>
GifEncoder
</TITLE>

<META NAME="keywords" CONTENT="com.gif4j.light.GifEncoder class">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">

<SCRIPT type="text/javascript">
function windowTitle()
{
    parent.document.title="GifEncoder";
}
</SCRIPT>

</HEAD>

<BODY BGCOLOR="white" onload="windowTitle();">

<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/GifEncoder.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;PREV CLASS&nbsp;
&nbsp;<A HREF="../../../com/gif4j/light/GifFrame.html" title="class in com.gif4j.light"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  <A HREF="../../../index.html" target="_top"><B>FRAMES</B></A>  &nbsp;
&nbsp;<A HREF="GifEncoder.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
&nbsp;<SCRIPT type="text/javascript">
  <!--
  if(window==top) {
    document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
  }
  //-->
</SCRIPT>
<NOSCRIPT>
  <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= -->

<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
com.gif4j.light</FONT>
<BR>
Class GifEncoder</H2>
<PRE>
java.lang.Object
  <IMG SRC="../../../resources/inherit.gif" ALT="extended by"><B>com.gif4j.light.GifEncoder</B>
</PRE>
<HR>
<DL>
<DT>public class <B>GifEncoder</B><DT>extends java.lang.Object</DL>

<P>
<p><code>GifEncoder</code> is a java class which takes as image(-s), encodes and saves it(them) out to a file or output stream using the GIF file format (GIF89a version). It can be used to save <code>Image</code> instances as non-animated GIF image files or prepared from the images sequence <code>GifImage</code> instances as animated GIF image files. If an encoding <code>Image</code> instance has more than 256 colors then before writing it as a GIF to the specified output stream it's automatically quantized to 256 unique colors. <code>GifEncoder</code> java class is thread safe and can be used without addittional synchronization.<br> </p> <p>The following 2 java examples demostrate common ways to use this java gif image encoder. Please peruse the API, tutorial and external examples for additional features.</p> <p> <h3>Save an image as a commented GIF file using Java</h3> <pre> import com.gif4j.light.GifEncoder; import com.gif4j.light.GifFrame; import com.gif4j.light.GifImage; import java.awt.*; import java.io.File; import java.io.IOException;     // ...   public void saveImageAsGif(Image image, String comment, File fileToSave)             throws IOException, InterruptedException {         // create new GifImage         GifImage gifImage = new GifImage();         // create new GifFrame         GifFrame gifFrame = new GifFrame(image);         // add GifFrame to GifImage         gifImage.addGifFrame(gifFrame);         // add our comment         gifImage.addComment(comment);         // save gifImage         GifEncoder.encode(gifImage, fileToSave);     } </pre> </p> <p> <h3>Save array of images as an animated GIF file using Java</h3> <pre> import com.gif4j.light.GifEncoder; import com.gif4j.light.GifFrame; import com.gif4j.light.GifImage; import java.awt.*; import java.io.File; import java.io.IOException;    // ...    public void saveImageArrayAsAnimatedGif(Image[] images, File fileToSave)            throws IOException, InterruptedException {        // create new GifImage instance        GifImage gifImage = new GifImage();        // set default delay between gif frames        gifImage.setDefaultDelay(200);        // set infinite looping (by default only 1 looping iteration is set)        gifImage.setLoopNumber(0);        // add comment to gif image        gifImage.addComment("Animated GIF image example");        // add images wrapped by GifFrame        for (int i = 0; i < images.length; i++){            GifFrame nextFrame = new GifFrame(images[i]);            // clear logic screen after every frame            nextFrame.setDisposalMethod(GifFrame.DISPOSAL_METHOD_RESTORE_TO_BACKGROUND_COLOR);            gifImage.addGifFrame(nextFrame);        }        // save animated gif image        GifEncoder.encode(gifImage, fileToSave);    } </pre> </p> <p><b>Note:</b> After encoding a <code>GifImage</code> instance and its' internal <code>GifFrame</code>(-s) are disposed to free memory and can't be reused!</p> The following specification "GRAPHICS INTERCHANGE FORMAT(sm) Version 89a" was referenced for the development of this encoder.<br> Some of the naming conventions and clarification of some aspects of GIF file format and LZW compression were obtained from the following:<br> LZW.C <br> Copyright (c) 1989 Mark R. Nelson<br> LZW data compression/expansion demonstration program.<br> May 12, 1997<br>
<P>

<P>
<DL>
<DT><B>Version:</B></DT>  <DD>1.0</DD><DT><B>Author:</B></DT>  <DD><a href="http://www.gif4j.com">Gif4J Software - Java GIF image processing solutions</a></DD><DT><B>See Also:</B><DD><A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light"><CODE>GifImage</CODE></A>, <CODE>Image</CODE></DL>
<HR>

<P>
<!-- ======== NESTED CLASS SUMMARY ======== -->


<!-- =========== FIELD SUMMARY =========== -->


<!-- ======== CONSTRUCTOR SUMMARY ======== -->


<!-- ========== METHOD SUMMARY =========== -->

<A NAME="method_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../com/gif4j/light/GifEncoder.html#encode(com.gif4j.light.GifImage, java.io.File)">encode</A></B>(<A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light">GifImage</A>&nbsp;gifImage,       java.io.File&nbsp;output)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode and write out the data contained in the <A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light"><CODE>GifImage</CODE></A> to a <code>File</code> in the GIF output format ('89a' version). </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../com/gif4j/light/GifEncoder.html#encode(com.gif4j.light.GifImage, java.io.File, boolean)">encode</A></B>(<A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light">GifImage</A>&nbsp;gifImage,       java.io.File&nbsp;output,       boolean&nbsp;forceGlobalColorTableUsage)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode and write out the data contained in the <A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light"><CODE>GifImage</CODE></A> to a <code>File</code> in the GIF output format ('89a' version). </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../com/gif4j/light/GifEncoder.html#encode(com.gif4j.light.GifImage, java.io.OutputStream)">encode</A></B>(<A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light">GifImage</A>&nbsp;gifImage,       java.io.OutputStream&nbsp;outputStream)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode and write out the data contained in the <A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light"><CODE>GifImage</CODE></A> to the specified output stream in the GIF image file format ('89a' version).</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../com/gif4j/light/GifEncoder.html#encode(com.gif4j.light.GifImage, java.io.OutputStream, boolean)">encode</A></B>(<A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light">GifImage</A>&nbsp;gifImage,       java.io.OutputStream&nbsp;outputStream,       boolean&nbsp;forceGlobalColorTableUsage)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode and write out the data contained in the <A HREF="../../../com/gif4j/light/GifImage.html" title="class in com.gif4j.light"><CODE>GifImage</CODE></A> to the specified output stream in the GIF file format ('89a' version).</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../com/gif4j/light/GifEncoder.html#encode(java.awt.Image, java.io.DataOutput)">encode</A></B>(java.awt.Image&nbsp;image,       java.io.DataOutput&nbsp;dataOutput)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode and write out the data contained in the <code>Image</code> to the specified output in the GIF89a file format.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../com/gif4j/light/GifEncoder.html#encode(java.awt.Image, java.io.File)">encode</A></B>(java.awt.Image&nbsp;image,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -