0

我刚刚在这里http://dke-tron.googlecode.com/svn-history/r39/trunk/src/nl/unimaas/games/tron/util/GifSequenceWriter.java偶然发现了这个 GifSequenceWriter 。构造函数的代码是这样的:

public GifSequenceWriter(
  ImageOutputStream outputStream,
  int imageType,
  int timeBetweenFramesMS,
  boolean loopContinuously) throws IIOException, IOException {
// my method to create a writer
gifWriter = getWriter(); 
imageWriteParam = gifWriter.getDefaultWriteParam();
ImageTypeSpecifier imageTypeSpecifier =
  ImageTypeSpecifier.createFromBufferedImageType(imageType);

imageMetaData =
  gifWriter.getDefaultImageMetadata(imageTypeSpecifier,
  imageWriteParam);

String metaFormatName = imageMetaData.getNativeMetadataFormatName();

IIOMetadataNode root = (IIOMetadataNode)
  imageMetaData.getAsTree(metaFormatName);

IIOMetadataNode graphicsControlExtensionNode = getNode(
  root,
  "GraphicControlExtension");

graphicsControlExtensionNode.setAttribute("disposalMethod", "none");
graphicsControlExtensionNode.setAttribute("userInputFlag", "FALSE");
graphicsControlExtensionNode.setAttribute(
  "transparentColorFlag",
  "FALSE");
graphicsControlExtensionNode.setAttribute(
  "delayTime",
  Integer.toString(timeBetweenFramesMS / 10));
graphicsControlExtensionNode.setAttribute(
  "transparentColorIndex",
  "0");

IIOMetadataNode commentsNode = getNode(root, "CommentExtensions");
commentsNode.setAttribute("CommentExtension", "Created by MAH");

IIOMetadataNode appEntensionsNode = getNode(
  root,
  "ApplicationExtensions");

IIOMetadataNode child = new IIOMetadataNode("ApplicationExtension");

child.setAttribute("applicationID", "NETSCAPE");
child.setAttribute("authenticationCode", "2.0");

int loop = loopContinuously ? 0 : 1;

child.setUserObject(new byte[]{ 0x1, (byte) (loop & 0xFF), (byte)
  ((loop >> 8) & 0xFF)});
appEntensionsNode.appendChild(child);

imageMetaData.setFromTree(metaFormatName, root);

gifWriter.setOutput(outputStream);

gifWriter.prepareWriteSequence(null);
}

根本不明白这个构造函数本质上在做什么?只是写一些元数据?有人可以解释一下吗?为什么需要元数据?

4

1 回答 1

1

构造函数显然正在设置,GifSequenceWriter以便将具有正确内容的初始元数据写入底层输出流。

可以在 中看到类似的行为ObjectOutputStream,其中构造函数将标头信息写入底层流。

于 2013-07-21T17:36:55.450 回答