﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-图形图像</title><link>http://www.cppblog.com/graphics518/</link><description>*.*</description><language>zh-cn</language><lastBuildDate>Tue, 28 Apr 2026 23:36:40 GMT</lastBuildDate><pubDate>Tue, 28 Apr 2026 23:36:40 GMT</pubDate><ttl>60</ttl><item><title>JGIF</title><link>http://www.cppblog.com/graphics518/archive/2005/10/09/596.html</link><dc:creator>Graphics</dc:creator><author>Graphics</author><pubDate>Sat, 08 Oct 2005 22:59:00 GMT</pubDate><guid>http://www.cppblog.com/graphics518/archive/2005/10/09/596.html</guid><wfw:comment>http://www.cppblog.com/graphics518/comments/596.html</wfw:comment><comments>http://www.cppblog.com/graphics518/archive/2005/10/09/596.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/graphics518/comments/commentRss/596.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/graphics518/services/trackbacks/596.html</trackback:ping><description><![CDATA[<P>　　<B>JGIF 是一个 Java 编写的 GIF 文件编码器</B>。除可以方便地把 BufferedImage 编码成 GIF 文件外，还具有高性能的 24 位色到 256 色的转化功能。</P>
<P>　　使用极其简便：</P>
<P>　　生成静态 GIF：</P><PRE class=code>import java.io.*;
import javax.imageio.*;

public class TestImage
{
  public static void main(String[] args) throws Exception
  {
    try{
      net.jgif.GIFImage image =
        new net.jgif.GIFImage(ImageIO.read(new File("1.jpg")));
      image.setCommentExtension("bout.toString()");//加入注解扩展
      /*
      指定版本号，如果指定为 GIF87A，则注解扩展及透明色实效。
      默认为 GIF89A。
      */
      //image.setVersion(net.jgif.GIFImage.GIF87A);
      /*
      指定其透明色，也可不指定。
      无论是否指定，在 BufferedImage 中为透明色的颜色一律透明。
      如果指定了透明色，则该颜色也将透明。
      */
      //image.setTransparenceColor(java.awt.Color.BLACK);
      //image.isInterlace = true;//指定是否进行交错处理（默认为false）。
      image.save(new FileOutputStream("test.gif"));
    }catch(Exception e){
      e.printStackTrace();
    }
  }
}
				</PRE>
<P>　　生成动画：</P><PRE class=code>import java.io.*;
import javax.imageio.*;

public class TestAnimator
{
  public static void main(String[] args) throws Exception
  {
    try{
      net.jgif.GIFAnimator image = new net.jgif.GIFAnimator();
      //设置循环次数，0 为无限循环，大于 0 为指定次数，默认为 0。
      image.setLoopCount(1);
      image.setCommentExtension("setCommentExtension");//加入注解说明扩展。
      //直接加入帧。
      image.addFrame(ImageIO.read(new File("1.jpg")));
      //以指定的时间加入帧。
      image.addFrame(ImageIO.read(new File("2.jpg")), 1000);
      //以可定义的帧的形式加入帧。
      net.jgif.GIFFrame frame = 
        new net.jgif.GIFFrame(ImageIO.read(new File("2.jpg")));
      //指定显示方案，默认为 DM_LEAVE。
      //frame.setDisposalMethod(net.jgif.GIFFrame.DM_BGCOLOR);
      //设置该帧的显示时间，单位为毫秒，如果不指定则为默认值 500，即 0.5 秒。
      frame.setDelayTime(1000);
      //指定frame在整幅图片中的位置。
      //frame.imageLeft = 10;
      //frame.imageTop = 10;
      /*
      指定其透明色，也可不指定。
      无论是否指定，在 BufferedImage 中为透明色的颜色一律透明。
      如果指定了透明色，则该颜色也将透明。
      */
      //frame.setTransparenceColor(java.awt.Color.BLACK);
      image.addFrame(frame);
      image.save(new FileOutputStream("test.gif"));
    }catch(Exception e){
      e.printStackTrace();
    }
  }
}
				</PRE>
<P><A href="http://www.graphics.net.cn/application/jgif.asp"><FONT color=#0061de>下载</FONT></A> <A href="mailto:graphics518@163.com"><FONT color=#0061de>联系作者</FONT></A></P><img src ="http://www.cppblog.com/graphics518/aggbug/596.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/graphics518/" target="_blank">Graphics</a> 2005-10-09 06:59 <a href="http://www.cppblog.com/graphics518/archive/2005/10/09/596.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>