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

📄 gifimagemetadata.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)GIFImageMetadata.java	1.31 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.imageio.plugins.gif;import java.io.UnsupportedEncodingException;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import javax.imageio.ImageTypeSpecifier;import javax.imageio.metadata.IIOInvalidTreeException;import javax.imageio.metadata.IIOMetadata;import javax.imageio.metadata.IIOMetadataNode;import javax.imageio.metadata.IIOMetadataFormat;import javax.imageio.metadata.IIOMetadataFormatImpl;import org.w3c.dom.Node;/** * @version 0.5 */public class GIFImageMetadata extends GIFMetadata {    // package scope    static final String        nativeMetadataFormatName = "javax_imageio_gif_image_1.0";    static final String[] disposalMethodNames = {        "none",        "doNotDispose",        "restoreToBackgroundColor",        "restoreToPrevious",        "undefinedDisposalMethod4",        "undefinedDisposalMethod5",        "undefinedDisposalMethod6",        "undefinedDisposalMethod7"    };    // Fields from Image Descriptor    public int imageLeftPosition;    public int imageTopPosition;    public int imageWidth;    public int imageHeight;    public boolean interlaceFlag = false;    public boolean sortFlag = false;    public byte[] localColorTable = null;    // Fields from Graphic Control Extension    public int disposalMethod = 0;    public boolean userInputFlag = false;    public boolean transparentColorFlag = false;    public int delayTime = 0;    public int transparentColorIndex = 0;    // Fields from Plain Text Extension    public boolean hasPlainTextExtension = false;    public int textGridLeft;    public int textGridTop;    public int textGridWidth;    public int textGridHeight;    public int characterCellWidth;    public int characterCellHeight;    public int textForegroundColor;    public int textBackgroundColor;    public byte[] text;    // Fields from ApplicationExtension    // List of byte[]    public List applicationIDs = null; // new ArrayList();    // List of byte[]    public List authenticationCodes = null; // new ArrayList();    // List of byte[]    public List applicationData = null; // new ArrayList();    // Fields from CommentExtension    // List of byte[]    public List comments = null; // new ArrayList();    protected GIFImageMetadata(boolean standardMetadataFormatSupported,                               String nativeMetadataFormatName,                               String nativeMetadataFormatClassName,                               String[] extraMetadataFormatNames,                               String[] extraMetadataFormatClassNames)    {        super(standardMetadataFormatSupported,              nativeMetadataFormatName,              nativeMetadataFormatClassName,              extraMetadataFormatNames,              extraMetadataFormatClassNames);    }        public GIFImageMetadata() {        this(true,              nativeMetadataFormatName,              "com.sun.imageio.plugins.gif.GIFImageMetadataFormat",              null, null);    }        public boolean isReadOnly() {        return true;    }    public Node getAsTree(String formatName) {        if (formatName.equals(nativeMetadataFormatName)) {            return getNativeTree();        } else if (formatName.equals                   (IIOMetadataFormatImpl.standardMetadataFormatName)) {            return getStandardTree();        } else {            throw new IllegalArgumentException("Not a recognized format!");        }    }    private String toISO8859(byte[] data) {        try {            return new String(data, "ISO-8859-1");        } catch (UnsupportedEncodingException e) {            return "";        }    }    private Node getNativeTree() {        IIOMetadataNode node; // scratch node        IIOMetadataNode root =            new IIOMetadataNode(nativeMetadataFormatName);        // Image descriptor        node = new IIOMetadataNode("ImageDescriptor");        node.setAttribute("imageLeftPosition",                          Integer.toString(imageLeftPosition));        node.setAttribute("imageTopPosition",                          Integer.toString(imageTopPosition));        node.setAttribute("imageWidth", Integer.toString(imageWidth));        node.setAttribute("imageHeight", Integer.toString(imageHeight));        node.setAttribute("interlaceFlag",                          interlaceFlag ? "true" : "false");        root.appendChild(node);        // Local color table        if (localColorTable != null) {            node = new IIOMetadataNode("LocalColorTable");            int numEntries = localColorTable.length/3;            node.setAttribute("sizeOfLocalColorTable",                              Integer.toString(numEntries));            node.setAttribute("sortFlag",                              sortFlag ? "TRUE" : "FALSE");                        for (int i = 0; i < numEntries; i++) {                IIOMetadataNode entry =                    new IIOMetadataNode("ColorTableEntry");                entry.setAttribute("index", Integer.toString(i));                int r = localColorTable[3*i] & 0xff;                int g = localColorTable[3*i + 1] & 0xff;                int b = localColorTable[3*i + 2] & 0xff;                entry.setAttribute("red", Integer.toString(r));                entry.setAttribute("green", Integer.toString(g));                entry.setAttribute("blue", Integer.toString(b));                node.appendChild(entry);            }            root.appendChild(node);        }        // Graphic control extension        node = new IIOMetadataNode("GraphicControlExtension");        node.setAttribute("disposalMethod",                          disposalMethodNames[disposalMethod]);        node.setAttribute("userInputFlag",                          userInputFlag ? "true" : "false");        node.setAttribute("transparentColorFlag",                          transparentColorFlag ? "true" : "false");        node.setAttribute("delayTime",                           Integer.toString(delayTime));        node.setAttribute("transparentColorIndex",                          Integer.toString(transparentColorIndex));        root.appendChild(node);        if (hasPlainTextExtension) {            node = new IIOMetadataNode("PlainTextExtension");            node.setAttribute("textGridLeft",                              Integer.toString(textGridLeft));            node.setAttribute("textGridTop",                              Integer.toString(textGridTop));            node.setAttribute("textGridWidth",                              Integer.toString(textGridWidth));            node.setAttribute("textGridHeight",                              Integer.toString(textGridHeight));            node.setAttribute("characterCellWidth",                              Integer.toString(characterCellWidth));            node.setAttribute("characterCellHeight",                              Integer.toString(characterCellHeight));            node.setAttribute("textForegroundColor",                              Integer.toString(textForegroundColor));            node.setAttribute("textBackgroundColor",                              Integer.toString(textBackgroundColor));            node.setAttribute("text", toISO8859(text));            root.appendChild(node);        }        // Application extensions        int numAppExtensions = applicationIDs == null ?            0 : applicationIDs.size();        if (numAppExtensions > 0) {            node = new IIOMetadataNode("ApplicationExtensions");            for (int i = 0; i < numAppExtensions; i++) {                IIOMetadataNode appExtNode =                    new IIOMetadataNode("ApplicationExtension");                byte[] applicationID = (byte[])applicationIDs.get(i);                appExtNode.setAttribute("applicationID",                                        toISO8859(applicationID));                byte[] authenticationCode = (byte[])authenticationCodes.get(i);

⌨️ 快捷键说明

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