當前位置: 首頁>>代碼示例>>Java>>正文


Java IIOMetadataNode類代碼示例

本文整理匯總了Java中javax.imageio.metadata.IIOMetadataNode的典型用法代碼示例。如果您正苦於以下問題:Java IIOMetadataNode類的具體用法?Java IIOMetadataNode怎麽用?Java IIOMetadataNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IIOMetadataNode類屬於javax.imageio.metadata包,在下文中一共展示了IIOMetadataNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: COMMarkerSegment

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
/**
 * Constructs a marker segment from a native tree node.  If the node
 * is an <code>IIOMetadataNode</code> and contains a user object,
 * that object is used rather than the string attribute.  If the
 * string attribute is used, the default encoding is used.
 */
COMMarkerSegment(Node node) throws IIOInvalidTreeException{
    super(JPEG.COM);
    if (node instanceof IIOMetadataNode) {
        IIOMetadataNode ourNode = (IIOMetadataNode) node;
        data = (byte []) ourNode.getUserObject();
    }
    if (data == null) {
        String comment =
            node.getAttributes().getNamedItem("comment").getNodeValue();
        if (comment != null) {
            data = comment.getBytes(); // Default encoding
        } else {
            throw new IIOInvalidTreeException("Empty comment node!", node);
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:COMMarkerSegment.java

示例2: createStandardMetadataNodeTree

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
public static IIOMetadataNode createStandardMetadataNodeTree() {
    /*
     * Create standard metadata tree with creation time in
     * Standard(Root)/Document/ImageCreationTime node
     */
    IIOMetadataNode createTimeNode = new IIOMetadataNode("ImageCreationTime");
    createTimeNode.setAttribute("year", "2016");
    createTimeNode.setAttribute("month", "12");
    createTimeNode.setAttribute("day", "21");
    createTimeNode.setAttribute("hour", "18");
    createTimeNode.setAttribute("minute", "30");
    createTimeNode.setAttribute("second", "00");

    // Create the Document node
    IIOMetadataNode documentNode = new IIOMetadataNode("Document");
    documentNode.appendChild(createTimeNode);

    // Create a root node append the Document node
    IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
    root.appendChild(documentNode);

    return root;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:PngCreationTimeTest.java

示例3: getNativeNode

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
IIOMetadataNode getNativeNode() {
    IIOMetadataNode node = new IIOMetadataNode("sos");
    node.setAttribute("numScanComponents",
                      Integer.toString(componentSpecs.length));
    node.setAttribute("startSpectralSelection",
                      Integer.toString(startSpectralSelection));
    node.setAttribute("endSpectralSelection",
                      Integer.toString(endSpectralSelection));
    node.setAttribute("approxHigh",
                      Integer.toString(approxHigh));
    node.setAttribute("approxLow",
                      Integer.toString(approxLow));
    for (int i = 0; i < componentSpecs.length; i++) {
        node.appendChild(componentSpecs[i].getNativeNode());
    }

    return node;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:SOSMarkerSegment.java

示例4: getNativeNode

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
/**
 * Returns a tree of DOM nodes representing this object and any
 * subordinate JFXX extension or ICC Profile segments.
 */
IIOMetadataNode getNativeNode() {
    IIOMetadataNode node = new IIOMetadataNode("app0JFIF");
    node.setAttribute("majorVersion", Integer.toString(majorVersion));
    node.setAttribute("minorVersion", Integer.toString(minorVersion));
    node.setAttribute("resUnits", Integer.toString(resUnits));
    node.setAttribute("Xdensity", Integer.toString(Xdensity));
    node.setAttribute("Ydensity", Integer.toString(Ydensity));
    node.setAttribute("thumbWidth", Integer.toString(thumbWidth));
    node.setAttribute("thumbHeight", Integer.toString(thumbHeight));
    if (!extSegments.isEmpty()) {
        IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX");
        node.appendChild(JFXXnode);
        for (Iterator iter = extSegments.iterator(); iter.hasNext();) {
            JFIFExtensionMarkerSegment seg =
                (JFIFExtensionMarkerSegment) iter.next();
            JFXXnode.appendChild(seg.getNativeNode());
        }
    }
    if (iccSegment != null) {
        node.appendChild(iccSegment.getNativeNode());
    }

    return node;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:JFIFMarkerSegment.java

示例5: getNativeNode

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
IIOMetadataNode getNativeNode() {
    IIOMetadataNode node = new IIOMetadataNode("sof");
    node.setAttribute("process", Integer.toString(tag-JPEG.SOF0));
    node.setAttribute("samplePrecision",
                      Integer.toString(samplePrecision));
    node.setAttribute("numLines",
                      Integer.toString(numLines));
    node.setAttribute("samplesPerLine",
                      Integer.toString(samplesPerLine));
    node.setAttribute("numFrameComponents",
                      Integer.toString(componentSpecs.length));
    for (int i = 0; i < componentSpecs.length; i++) {
        node.appendChild(componentSpecs[i].getNativeNode());
    }

    return node;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:SOFMarkerSegment.java

示例6: getStandardChromaNode

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
protected IIOMetadataNode getStandardChromaNode() {

        if ((palette != null) && (paletteSize > 0)) {
            IIOMetadataNode node = new IIOMetadataNode("Chroma");
            IIOMetadataNode subNode = new IIOMetadataNode("Palette");
            int numComps = palette.length / paletteSize;
            subNode.setAttribute("value", "" + numComps);

            for (int i = 0, j = 0; i < paletteSize; i++) {
                IIOMetadataNode subNode1 = new IIOMetadataNode("PaletteEntry");
                subNode1.setAttribute("index", ""+i);
                subNode1.setAttribute("red", "" + palette[j++]);
                subNode1.setAttribute("green", "" + palette[j++]);
                subNode1.setAttribute("blue", "" + palette[j++]);
                if (numComps == 4 && palette[j] != 0)
                    subNode1.setAttribute("alpha", "" + palette[j++]);
                subNode.appendChild(subNode1);
            }
            node.appendChild(subNode);
            return node;
        }

        return null;
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:BMPMetadata.java

示例7: getStandardDataNode

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
protected IIOMetadataNode getStandardDataNode() {
    IIOMetadataNode node = new IIOMetadataNode("Data");

    String bits = "";
    if (bitsPerPixel == 24)
        bits = "8 8 8 ";
    else if (bitsPerPixel == 16 || bitsPerPixel == 32) {
        bits = "" + countBits(redMask) + " " + countBits(greenMask) +
              countBits(blueMask) + "" + countBits(alphaMask);
    }

    IIOMetadataNode subNode = new IIOMetadataNode("BitsPerSample");
    subNode.setAttribute("value", bits);
    node.appendChild(subNode);

    return node;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:BMPMetadata.java

示例8: gethISTNode

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:ShortHistogramTest.java

示例9: test1

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
public static void test1() {
    IIOMetadataNode parent = new IIOMetadataNode("parent");
    IIOMetadataNode elem   = new IIOMetadataNode("elem");

    MyAttrNode attrNode = new MyAttrNode("name", "value");
    elem.setAttributeNode(attrNode);
    attrNode.setOwnerElement(elem);

    try {
        parent.setAttributeNode(attrNode);
    } catch (DOMException e) {
        if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) {
            throw new RuntimeException("Test 1 failed: " +
                                       "Invalid exception code: " +
                                       e.code);
        }
        return;
    }

    throw new RuntimeException("Test 1 failed: DOMException not thrown");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:SetAttributeNode.java

示例10: readFrom

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
private static ITXtTest readFrom(File f) {
    try (ImageInputStream imageInputStream =
            ImageIO.createImageInputStream(f)) {

        ImageReader r = ImageIO.getImageReaders(imageInputStream).next();
        r.setInput(imageInputStream);

        IIOImage dst = r.readAll(0, null);

        // look for iTXt node
        IIOMetadata m = dst.getMetadata();
        Node root = m.getAsTree(m.getNativeMetadataFormatName());
        Node n = root.getFirstChild();
        while (n != null && !"iTXt".equals(n.getNodeName())) {
            n = n.getNextSibling();
        }
        if (n == null) {
            throw new RuntimeException("No iTXt node!");
        }
        ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
        return t;
    } catch (Throwable e) {
        throw new RuntimeException("Reading test failed.", e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:ITXtTest.java

示例11: test2

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
public static void test2() {
    String name = "attr";
    String oldValue = "old value";
    String newValue = "new value";
    Attr retAttr;

    IIOMetadataNode parent = new IIOMetadataNode("parent");
    MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
    MyAttrNode attrNode2 = new MyAttrNode(name, newValue);

    retAttr = parent.setAttributeNode(attrNode1);
    retAttr = parent.setAttributeNode(attrNode2);

    String actName = retAttr.getNodeName();
    String actValue = retAttr.getValue();

    if (!actName.equals(name) || !actValue.equals(oldValue)) {
        throw new RuntimeException("Test 2 failed: Invalid attribute " +
                                   "returned: " +
                                   "(name: " + actName +
                                   ", value: " + actValue + ")");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:SetAttributeNode.java

示例12: test4

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
public static void test4() {
    String name = "name";
    String correctValue = "correct value";
    String wrongValue = "wrong value";

    IIOMetadataNode parent = new IIOMetadataNode("parent");
    MyAttrNode attrNode1 = new MyAttrNode(name, wrongValue);
    MyAttrNode attrNode2 = new MyAttrNode(name, correctValue);

    parent.setAttributeNode(attrNode1);
    parent.setAttributeNode(attrNode2);

    Attr actAttr = parent.getAttributeNode(name);
    String actValue = actAttr.getValue();

    if (!actValue.equals(correctValue)) {
        throw new RuntimeException("Test 4 failed: Return value is: " +
                                   actValue);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:SetAttributeNode.java

示例13: getFromNode

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
public static ITXtTest getFromNode(IIOMetadataNode n) {
    ITXtTest t = new ITXtTest();

    if (!"iTXt".equals(n.getNodeName())) {
        throw new RuntimeException("Invalid node");
    }
    IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
    if (!"iTXtEntry".equals(e.getNodeName())) {
        throw new RuntimeException("Invalid entry node");
    }
    t.keyword = e.getAttribute("keyword");
    t.isCompressed =
        Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
    t.compression =
        Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
    t.language = e.getAttribute("languageTag");
    t.trasKeyword = e.getAttribute("translatedKeyword");
    t.text = e.getAttribute("text");

    return t;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:ITXtTest.java

示例14: readFrom

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
private static ITXtTest readFrom(File f) {
    try {
        ImageInputStream iis = ImageIO.createImageInputStream(f);
        ImageReader r = ImageIO.getImageReaders(iis).next();
        r.setInput(iis);

        IIOImage dst = r.readAll(0, null);

        // look for iTXt node
        IIOMetadata m = dst.getMetadata();
        Node root = m.getAsTree(m.getNativeMetadataFormatName());
        Node n = root.getFirstChild();
        while (n != null && !"iTXt".equals(n.getNodeName())) {
            n = n.getNextSibling();
        }
        if (n == null) {
            throw new RuntimeException("No iTXt node!");
        }
        ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
        return t;
    } catch (Throwable e) {
        throw new RuntimeException("Reading test failed.", e);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:ITXtTest.java

示例15: COMMarkerSegment

import javax.imageio.metadata.IIOMetadataNode; //導入依賴的package包/類
/**
 * Constructs a marker segment from a native tree node.  If the node
 * is an {@code IIOMetadataNode} and contains a user object,
 * that object is used rather than the string attribute.  If the
 * string attribute is used, the default encoding is used.
 */
COMMarkerSegment(Node node) throws IIOInvalidTreeException{
    super(JPEG.COM);
    if (node instanceof IIOMetadataNode) {
        IIOMetadataNode ourNode = (IIOMetadataNode) node;
        data = (byte []) ourNode.getUserObject();
    }
    if (data == null) {
        String comment =
            node.getAttributes().getNamedItem("comment").getNodeValue();
        if (comment != null) {
            data = comment.getBytes(); // Default encoding
        } else {
            throw new IIOInvalidTreeException("Empty comment node!", node);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:COMMarkerSegment.java


注:本文中的javax.imageio.metadata.IIOMetadataNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。