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

📄 pngmetadata.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                                  Integer.toString(sBIT_greenBits));                node.setAttribute("blue",                                  Integer.toString(sBIT_blueBits));                node.setAttribute("alpha",                                  Integer.toString(sBIT_alphaBits));            } else if (sBIT_colorType == PNGImageReader.PNG_COLOR_PALETTE) {                node = new IIOMetadataNode("sBIT_Palette");                node.setAttribute("red",                                  Integer.toString(sBIT_redBits));                node.setAttribute("green",                                  Integer.toString(sBIT_greenBits));                node.setAttribute("blue",                                  Integer.toString(sBIT_blueBits));            }            sBIT_node.appendChild(node);                            root.appendChild(sBIT_node);        }        // sPLT        if (sPLT_present) {            IIOMetadataNode sPLT_node = new IIOMetadataNode("sPLT");            sPLT_node.setAttribute("name", sPLT_paletteName);            sPLT_node.setAttribute("sampleDepth",                                   Integer.toString(sPLT_sampleDepth));            int numEntries = sPLT_red.length;            for (int i = 0; i < numEntries; i++) {                IIOMetadataNode entry = new IIOMetadataNode("sPLTEntry");                entry.setAttribute("index", Integer.toString(i));                entry.setAttribute("red", Integer.toString(sPLT_red[i]));                entry.setAttribute("green", Integer.toString(sPLT_green[i]));                entry.setAttribute("blue", Integer.toString(sPLT_blue[i]));                entry.setAttribute("alpha", Integer.toString(sPLT_alpha[i]));                entry.setAttribute("frequency",                                  Integer.toString(sPLT_frequency[i]));                sPLT_node.appendChild(entry);            }            root.appendChild(sPLT_node);        }        // sRGB        if (sRGB_present) {            IIOMetadataNode sRGB_node = new IIOMetadataNode("sRGB");            sRGB_node.setAttribute("renderingIntent",                                   renderingIntentNames[sRGB_renderingIntent]);            root.appendChild(sRGB_node);        }        // tEXt        if (tEXt_keyword.size() > 0) {            IIOMetadataNode tEXt_parent = new IIOMetadataNode("tEXt");            for (int i = 0; i < tEXt_keyword.size(); i++) {                IIOMetadataNode tEXt_node = new IIOMetadataNode("tEXtEntry");                tEXt_node.setAttribute("keyword" , (String)tEXt_keyword.get(i));                tEXt_node.setAttribute("value" , (String)tEXt_text.get(i));                                tEXt_parent.appendChild(tEXt_node);            }                            root.appendChild(tEXt_parent);        }        // tIME        if (tIME_present) {            IIOMetadataNode tIME_node = new IIOMetadataNode("tIME");            tIME_node.setAttribute("year", Integer.toString(tIME_year));            tIME_node.setAttribute("month", Integer.toString(tIME_month));            tIME_node.setAttribute("day", Integer.toString(tIME_day));            tIME_node.setAttribute("hour", Integer.toString(tIME_hour));            tIME_node.setAttribute("minute", Integer.toString(tIME_minute));            tIME_node.setAttribute("second", Integer.toString(tIME_second));            root.appendChild(tIME_node);        }        // tRNS        if (tRNS_present) {            IIOMetadataNode tRNS_node = new IIOMetadataNode("tRNS");            if (tRNS_colorType == PNGImageReader.PNG_COLOR_PALETTE) {                node = new IIOMetadataNode("tRNS_Palette");                                for (int i = 0; i < tRNS_alpha.length; i++) {                    IIOMetadataNode entry =                        new IIOMetadataNode("tRNS_PaletteEntry");                    entry.setAttribute("index", Integer.toString(i));                    entry.setAttribute("alpha",                                       Integer.toString(tRNS_alpha[i] & 0xff));                    node.appendChild(entry);                }            } else if (tRNS_colorType == PNGImageReader.PNG_COLOR_GRAY) {                node = new IIOMetadataNode("tRNS_Grayscale");                node.setAttribute("gray", Integer.toString(tRNS_gray));            } else if (tRNS_colorType == PNGImageReader.PNG_COLOR_RGB) {                node = new IIOMetadataNode("tRNS_RGB");                node.setAttribute("red", Integer.toString(tRNS_red));                node.setAttribute("green", Integer.toString(tRNS_green));                node.setAttribute("blue", Integer.toString(tRNS_blue));            }            tRNS_node.appendChild(node);                        root.appendChild(tRNS_node);        }        // zTXt        if (zTXt_keyword.size() > 0) {            IIOMetadataNode zTXt_parent = new IIOMetadataNode("zTXt");            for (int i = 0; i < zTXt_keyword.size(); i++) {                IIOMetadataNode zTXt_node = new IIOMetadataNode("zTXtEntry");                zTXt_node.setAttribute("keyword", (String)zTXt_keyword.get(i));                int cm = ((Integer)zTXt_compressionMethod.get(i)).intValue();                zTXt_node.setAttribute("compressionMethod",                                       zTXt_compressionMethodNames[cm]);                zTXt_node.setAttribute("text", (String)zTXt_text.get(i));                zTXt_parent.appendChild(zTXt_node);            }            root.appendChild(zTXt_parent);        }                // Unknown chunks        if (unknownChunkType.size() > 0) {            IIOMetadataNode unknown_parent =                new IIOMetadataNode("UnknownChunks");            for (int i = 0; i < unknownChunkType.size(); i++) {                IIOMetadataNode unknown_node =                    new IIOMetadataNode("UnknownChunk");                unknown_node.setAttribute("type",                                          (String)unknownChunkType.get(i));                unknown_node.setUserObject((byte[])unknownChunkData.get(i));                                unknown_parent.appendChild(unknown_node);            }                        root.appendChild(unknown_parent);        }        return root;    }    private int getNumChannels() {        // Determine number of channels        // Be careful about palette color with transparency        int numChannels = IHDR_numChannels[IHDR_colorType];        if (IHDR_colorType == PNGImageReader.PNG_COLOR_PALETTE &&            tRNS_present && tRNS_colorType == IHDR_colorType) {            numChannels = 4;        }        return numChannels;    }    public IIOMetadataNode getStandardChromaNode() {        IIOMetadataNode chroma_node = new IIOMetadataNode("Chroma");        IIOMetadataNode node = null; // scratch node        node = new IIOMetadataNode("ColorSpaceType");        node.setAttribute("name", colorSpaceTypeNames[IHDR_colorType]);        chroma_node.appendChild(node);        node = new IIOMetadataNode("NumChannels");        node.setAttribute("value", Integer.toString(getNumChannels()));        chroma_node.appendChild(node);        if (gAMA_present) {            node = new IIOMetadataNode("Gamma");            node.setAttribute("value", Float.toString(gAMA_gamma*1.0e-5F));            chroma_node.appendChild(node);        }        node = new IIOMetadataNode("BlackIsZero");        node.setAttribute("value", "true");        chroma_node.appendChild(node);        if (PLTE_present) {            boolean hasAlpha = tRNS_present &&                (tRNS_colorType == PNGImageReader.PNG_COLOR_PALETTE);            node = new IIOMetadataNode("Palette");            for (int i = 0; i < PLTE_red.length; i++) {                IIOMetadataNode entry =                    new IIOMetadataNode("PaletteEntry");                entry.setAttribute("index", Integer.toString(i));                entry.setAttribute("red",                                   Integer.toString(PLTE_red[i] & 0xff));                entry.setAttribute("green",                                   Integer.toString(PLTE_green[i] & 0xff));                entry.setAttribute("blue",                                   Integer.toString(PLTE_blue[i] & 0xff));                if (hasAlpha) {		    int alpha = (i < tRNS_alpha.length) ?			(tRNS_alpha[i] & 0xff) : 255;                    entry.setAttribute("alpha", Integer.toString(alpha));                }                node.appendChild(entry);            }            chroma_node.appendChild(node);        }        if (bKGD_present) {            if (bKGD_colorType == PNGImageReader.PNG_COLOR_PALETTE) {                node = new IIOMetadataNode("BackgroundIndex");                node.setAttribute("value", Integer.toString(bKGD_index));            } else {                node = new IIOMetadataNode("BackgroundColor");                int r, g, b;                if (bKGD_colorType == PNGImageReader.PNG_COLOR_GRAY) {                    r = g = b = bKGD_gray;                } else {                    r = bKGD_red;                    g = bKGD_green;                    b = bKGD_blue;                }                node.setAttribute("red", Integer.toString(r));                node.setAttribute("green", Integer.toString(g));                node.setAttribute("blue", Integer.toString(b));            }            chroma_node.appendChild(node);        }        return chroma_node;    }    public IIOMetadataNode getStandardCompressionNode() {        IIOMetadataNode compression_node = new IIOMetadataNode("Compression");        IIOMetadataNode node = null; // scratch node        node = new IIOMetadataNode("CompressionTypeName");        node.setAttribute("value", "deflate");        compression_node.appendChild(node);        node = new IIOMetadataNode("Lossless");        node.setAttribute("value", "true");        compression_node.appendChild(node);        node = new IIOMetadataNode("NumProgressiveScans");        node.setAttribute("value",                          (IHDR_interlaceMethod == 0) ? "1" : "7");        compression_node.appendChild(node);        return compression_node;    }    private String repeat(String s, int times) {        if (times == 1) {            return s;        }        StringBuffer sb = new StringBuffer((s.length() + 1)*times - 1);        sb.append(s);        for (int i = 1; i < times; i++) {            sb.append(" ");            sb.append(s);        }        return sb.toString();    }    public IIOMetadataNode getStandardDataNode() {        IIOMetadataNode data_node = new IIOMetadataNode("Data");        IIOMetadataNode node = null; // scratch node        node = new IIOMetadataNode("PlanarConfiguration");        node.setAttribute("value", "PixelInterleaved");        data_node.appendChild(node);        node = new IIOMetadataNode("SampleFormat");        node.setAttribute("value",                          IHDR_colorType == PNGImageReader.PNG_COLOR_PALETTE ?                          "Index" : "UnsignedIntegral");        data_node.appendChild(node);        String bitDepth = Integer.toString(IHDR_bitDepth);        node = new IIOMetadataNode("BitsPerSample");        node.setAttribute("value", repeat(bitDepth, getNumChannels()));        data_node.appendChild(node);        if (sBIT_present) {            node = new IIOMetadataNode("SignificantBitsPerSample");            String sbits;            if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY ||                sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA) {                sbits = Integer.toString(sBIT_grayBits);            } else { // sBIT_colorType == PNGImageReader.PNG_COLOR_RGB ||                     // sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA                sbits = Integer.toString(sBIT_redBits) + " " +                     Integer.toString(sBIT_greenBits) + " " +                     Integer.toString(sBIT_blueBits);            }            if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA ||                sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA) {                sbits += " " + Integer.toString(sBIT_alphaBits);            }                        node.setAttribute("value", sbits);            data_node.appendChild(node);        }        // SampleMSB        return data_node;    }    public IIOMetadataNode getStandardDimensionNode() {        IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension");        IIOMetadataNode node = null; // scratch node        node = new IIOMetadataNode("PixelAspectRatio");        float ratio = pHYs_present ?            (float)pHYs_pixelsPerUnitXAxis/pHYs_pixelsPerUnitYAxis : 1.0F;        node.setAttribute("value", Float.toString(ratio));        dimension_node.appendChild(node);                node = new IIOMetadataNode("ImageOrientation");        node.setAttribute("value", "Normal");        dimension_node.appendChild(node);

⌨️ 快捷键说明

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