package net.jmge.gif;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;
//==============================================================================
/** This is the central class of a JDK 1.1 compatible GIF encoder that, AFAIK,
* supports more features of the extended GIF spec than any other Java open
* source encoder. Some sections of the source are lifted or adapted from Jef
* Poskanzer's <cite>Acme GifEncoder</cite> (so please see the
* <a href="../readme.txt">readme</a> containing his notice), but much of it,
* including nearly all of the present class, is original code. My main
* motivation for writing a new encoder was to support animated GIFs, but the
* package also adds support for embedded textual comments.
* <p>
* There are still some limitations. For instance, animations are limited to
* a single global color table. But that is usually what you want anyway, so
* as to avoid irregularities on some displays. (So this is not really a
* limitation, but a "disciplinary feature" :) Another rather more serious
* restriction is that the total number of RGB colors in a given input-batch
* mustn't exceed 256. Obviously, there is an opening here for someone who
* would like to add a color-reducing preprocessor.
* <p>
* The encoder, though very usable in its present form, is at bottom only a
* partial implementation skewed toward my own particular needs. Hence a
* couple of caveats are in order. (1) During development it was in the back
* of my mind that an encoder object should be reusable - i.e., you should be
* able to make multiple calls to encode() on the same object, with or without
* intervening frame additions or changes to options. But I haven't reviewed
* the code with such usage in mind, much less tested it, so it's likely I
* overlooked something. (2) The encoder classes aren't thread safe, so use
* caution in a context where access is shared by multiple threads. (Better
* yet, finish the library and re-release it :)
* <p>
* There follow a couple of simple examples illustrating the most common way to
* use the encoder, i.e., to encode AWT Image objects created elsewhere in the
* program. Use of some of the most popular format options is also shown,
* though you will want to peruse the API for additional features.
*
* <p>
* <strong>Animated GIF Example</strong>
* <pre>
* import net.jmge.gif.Gif89Encoder;
* // ...
* void writeAnimatedGIF(Image[] still_images,
* String annotation,
* boolean looped,
* double frames_per_second,
* OutputStream out) throws IOException
* {
* Gif89Encoder gifenc = new Gif89Encoder();
* for (int i = 0; i < still_images.length; ++i)
* gifenc.addFrame(still_images[i]);
* gifenc.setComments(annotation);
* gifenc.setLoopCount(looped ? 0 : 1);
* gifenc.setUniformDelay((int) Math.round(100 / frames_per_second));
* gifenc.encode(out);
* }
* </pre>
*
* <strong>Static GIF Example</strong>
* <pre>
* import net.jmge.gif.Gif89Encoder;
* // ...
* void writeNormalGIF(Image img,
* String annotation,
* int transparent_index, // pass -1 for none
* boolean interlaced,
* OutputStream out) throws IOException
* {
* Gif89Encoder gifenc = new Gif89Encoder(img);
* gifenc.setComments(annotation);
* gifenc.setTransparentIndex(transparent_index);
* gifenc.getFrameAt(0).setInterlaced(interlaced);
* gifenc.encode(out);
* }
* </pre>
*
* @version 0.90 beta (15-Jul-2000)
* @author J. M. G. Elliott (tep@jmge.net)
* @see Gif89Frame
* @see DirectGif89Frame
* @see IndexGif89Frame
*/
public class Gif89Encoder {
private Dimension dispDim = new Dimension(0, 0);
private GifColorTable colorTable;
private int bgIndex = 0;
private int loopCount = 1;
private String theComments;
private Vector vFrames = new Vector();
//----------------------------------------------------------------------------
/** Use this default constructor if you'll be adding multiple frames
* constructed from RGB data (i.e., AWT Image objects or ARGB-pixel arrays).
*/
public Gif89Encoder()
{
// empty color table puts us into "palette autodetect" mode
colorTable = new GifColorTable();
}
//----------------------------------------------------------------------------
/** Like the default except that it also adds a single frame, for conveniently
* encoding a static GIF from an image.
*
* @param static_image
* Any Image object that supports pixel-grabbing.
* @exception IOException
* See the addFrame() methods.
*/
public Gif89Encoder(Image static_image) throws IOException
{
this();
addFrame(static_image);
}
//----------------------------------------------------------------------------
/** This constructor installs a user color table, overriding the detection of
* of a palette from ARBG pixels.
*
* Use of this constructor imposes a couple of restrictions:
* (1) Frame objects can't be of type DirectGif89Frame
* (2) Transparency, if desired, must be set explicitly.
*
* @param colors
* Array of color values; no more than 256 colors will be read, since that's
* the limit for a GIF.
*/
public Gif89Encoder(Color[] colors)
{
colorTable = new GifColorTable(colors);
}
//----------------------------------------------------------------------------
/** Convenience constructor for encoding a static GIF from index-model data.
* Adds a single frame as specified.
*
* @param colors
* Array of color values; no more than 256 colors will be read, since
* that's the limit for a GIF.
* @param width
* Width of the GIF bitmap.
* @param height
* Height of same.
* @param ci_pixels
* Array of color-index pixels no less than width * height in length.
* @exception IOException
* See the addFrame() methods.
*/
public Gif89Encoder(Color[] colors, int width, int height, byte ci_pixels[])
throws IOException
{
this(colors);
addFrame(width, height, ci_pixels);
}
//----------------------------------------------------------------------------
/** Get the number of frames that have been added so far.
*
* @return
* Number of frame items.
*/
public int getFrameCount() { return vFrames.size(); }
//----------------------------------------------------------------------------
/** Get a reference back to a Gif89Frame object by position.
*
* @param index
* Zero-based index of the frame in the sequence.
* @return
* Gif89Frame object at the specified position (or null if no such frame).
*/
public Gif89Frame getFrameAt(int index)
{
return isOk(index) ? (Gif89Frame) vFrames.elementAt(index) : null;
}
//----------------------------------------------------------------------------
/** Add a Gif89Frame frame to the end of the internal sequence. Note that
* there are restrictions on the Gif89Frame type: if the encoder object was
* constructed with an explicit color table, an attempt to add a
* DirectGif89Frame will throw an exception.
*
* @param gf
* An externally constructed Gif89Frame.
* @exception IOException
* If Gif89Frame can't be accommodated. This could happen if either (1) the
*
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
jbarcode.jar (153个子文件)
stylesheet.css 1KB
inherit.gif 57B
index-all.html 76KB
JBarcodeComponent.html 36KB
BarSet.html 32KB
JBarcode.html 29KB
InvalidAtributeException.html 26KB
SwingDemo.html 24KB
BarcodeEncoder.html 22KB
CodabarEncoder.html 21KB
JBarcodeFactory.html 20KB
Code128Encoder.html 19KB
Code93Encoder.html 18KB
Code93ExtEncoder.html 18KB
TextPainter.html 17KB
Code39ExtEncoder.html 17KB
MSIPlesseyEncoder.html 17KB
ImageUtil.html 16KB
Standard2of5Encoder.html 16KB
Code39Encoder.html 16KB
BarcodePainter.html 16KB
Code11Encoder.html 16KB
EANEncoder.html 16KB
UPCEEncoder.html 16KB
JBarcode.html 15KB
UPCAEncoder.html 15KB
EAN13Encoder.html 15KB
PostNetEncoder.html 14KB
overview-tree.html 14KB
constant-values.html 14KB
Interleaved2of5Encoder.html 14KB
EAN8Encoder.html 13KB
BarSet.html 13KB
InvalidAtributeException.html 12KB
package-use.html 12KB
BarcodeEncoder.html 11KB
WideRatioCodedPainter.html 10KB
HeightCodedPainter.html 10KB
package-summary.html 10KB
package-tree.html 10KB
serialized-form.html 10KB
CircularPainter.html 10KB
WidthCodedPainter.html 10KB
BaseLineTextPainter.html 10KB
EAN13TextPainter.html 10KB
UPCETextPainter.html 10KB
EAN8TextPainter.html 10KB
UPCATextPainter.html 10KB
help-doc.html 9KB
SimpleDemo.html 9KB
Standard2of5Encoder.html 9KB
TextPainter.html 9KB
BarcodePainter.html 9KB
package-tree.html 9KB
package-summary.html 8KB
EANEncoder.html 8KB
package-use.html 8KB
CodabarEncoder.html 7KB
Code128Encoder.html 7KB
PostNetEncoder.html 7KB
EAN13Encoder.html 7KB
UPCEEncoder.html 7KB
UPCAEncoder.html 7KB
EAN8Encoder.html 7KB
Code39Encoder.html 7KB
Code93Encoder.html 7KB
JBarcodeFactory.html 7KB
package-use.html 7KB
package-tree.html 6KB
package-summary.html 6KB
package-summary.html 6KB
package-tree.html 6KB
overview-summary.html 6KB
package-summary.html 6KB
Interleaved2of5Encoder.html 6KB
WideRatioCodedPainter.html 6KB
BaseLineTextPainter.html 6KB
MSIPlesseyEncoder.html 6KB
HeightCodedPainter.html 6KB
Code39ExtEncoder.html 6KB
Code93ExtEncoder.html 6KB
WidthCodedPainter.html 6KB
EAN13TextPainter.html 6KB
EAN8TextPainter.html 6KB
UPCATextPainter.html 6KB
CircularPainter.html 6KB
UPCETextPainter.html 6KB
Code11Encoder.html 6KB
package-tree.html 6KB
SimpleDemo.html 6KB
ImageUtil.html 6KB
SwingDemo.html 6KB
JBarcodeComponent.html 6KB
package-use.html 5KB
package-use.html 5KB
allclasses-frame.html 5KB
deprecated-list.html 5KB
allclasses-noframe.html 4KB
package-frame.html 3KB
package-frame.html 2KB
共 153 条
- 1
- 2
qq_15120551
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页