当前位置: 首页>>代码示例>>Java>>正文


Java IIOMetadata.getAsTree方法代码示例

本文整理汇总了Java中javax.imageio.metadata.IIOMetadata.getAsTree方法的典型用法代码示例。如果您正苦于以下问题:Java IIOMetadata.getAsTree方法的具体用法?Java IIOMetadata.getAsTree怎么用?Java IIOMetadata.getAsTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.imageio.metadata.IIOMetadata的用法示例。


在下文中一共展示了IIOMetadata.getAsTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeHeader

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
private void writeHeader(IIOMetadata streamMetadata, int bitsPerPixel)
  throws IOException {

    GIFWritableStreamMetadata sm;
    if (streamMetadata instanceof GIFWritableStreamMetadata) {
        sm = (GIFWritableStreamMetadata)streamMetadata;
    } else {
        sm = new GIFWritableStreamMetadata();
        Node root =
            streamMetadata.getAsTree(STREAM_METADATA_NAME);
        sm.setFromTree(STREAM_METADATA_NAME, root);
    }

    writeHeader(sm.version,
                sm.logicalScreenWidth,
                sm.logicalScreenHeight,
                sm.colorResolution,
                sm.pixelAspectRatio,
                sm.backgroundColorIndex,
                sm.sortFlag,
                bitsPerPixel,
                sm.globalColorTable);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:GIFImageWriter.java

示例2: readFrom

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的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

示例3: upgradeMetadata

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
    String format = src.getNativeMetadataFormatName();
    System.out.println("Native format: " + format);
    Node root = src.getAsTree(format);

    // add hIST node
    Node n = lookupChildNode(root, "hIST");
    if (n == null) {
        System.out.println("Appending new hIST node...");
        Node hIST = gethISTNode(bi);
        root.appendChild(hIST);
    }

    System.out.println("Upgraded metadata tree:");
    dump(root, "");

    System.out.println("Merging metadata...");
    try {
        src.mergeTree(format, root);
    } catch (IIOInvalidTreeException e) {
        throw new RuntimeException("Test FAILED!", e);
    }
    return src;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ShortHistogramTest.java

示例4: convertStandardImageMetadata

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
/**
 * Converts a standard {@code javax_imageio_1.0} tree to a
 * {@code TIFFImageMetadata} object.
 *
 * @param inData The metadata object.
 * @return a {@code TIFFImageMetadata} or {@code null} if
 * the standard tree derived from the input object is {@code null}.
 * @throws IllegalArgumentException if {@code inData} is
 * {@code null}.
 * @throws IllegalArgumentException if {@code inData} does not support
 * the standard metadata format.
 * @throws IIOInvalidTreeException if {@code inData} generates an
 * invalid standard metadata tree.
 */
private TIFFImageMetadata convertStandardImageMetadata(IIOMetadata inData)
    throws IIOInvalidTreeException {

    if(inData == null) {
        throw new NullPointerException("inData == null!");
    } else if(!inData.isStandardMetadataFormatSupported()) {
        throw new IllegalArgumentException
            ("inData does not support standard metadata format!");
    }

    TIFFImageMetadata outData = null;

    String formatName = IIOMetadataFormatImpl.standardMetadataFormatName;
    Node tree = inData.getAsTree(formatName);
    if (tree != null) {
        List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
        tagSets.add(BaselineTIFFTagSet.getInstance());
        outData = new TIFFImageMetadata(tagSets);
        outData.setFromTree(formatName, tree);
    }

    return outData;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:TIFFImageWriter.java

示例5: convertNativeImageMetadata

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
/**
 * Converts a native
 * {@code javax_imageio_tiff_image_1.0} tree to a
 * {@code TIFFImageMetadata} object.
 *
 * @param inData The metadata object.
 * @return a {@code TIFFImageMetadata} or {@code null} if
 * the native tree derived from the input object is {@code null}.
 * @throws IllegalArgumentException if {@code inData} is
 * {@code null} or does not support the native metadata format.
 * @throws IIOInvalidTreeException if {@code inData} generates an
 * invalid native metadata tree.
 */
private TIFFImageMetadata convertNativeImageMetadata(IIOMetadata inData)
    throws IIOInvalidTreeException {

    if(inData == null) {
        throw new NullPointerException("inData == null!");
    } else if(!Arrays.asList(inData.getMetadataFormatNames()).contains(
                  TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME)) {
        throw new IllegalArgumentException
            ("inData does not support native metadata format!");
    }

    TIFFImageMetadata outData = null;

    String formatName = TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME;
    Node tree = inData.getAsTree(formatName);
    if (tree != null) {
        List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
        tagSets.add(BaselineTIFFTagSet.getInstance());
        outData = new TIFFImageMetadata(tagSets);
        outData.setFromTree(formatName, tree);
    }

    return outData;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:TIFFImageWriter.java

示例6: main

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    // Generate some trivial image and save it to a temporary array
    ByteArrayOutputStream tmp = new ByteArrayOutputStream();
    ImageIO.write(new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB),
            "gif", tmp);

    // Read the stream
    ImageInputStream in = new MemoryCacheImageInputStream(
            new ByteArrayInputStream(tmp.toByteArray()));
    ImageReader reader = ImageIO.getImageReaders(in).next();
    reader.setInput(in);

    // Retrieve standard image metadata tree
    IIOMetadata meta = reader.getImageMetadata(0);
    if (meta == null || !meta.isStandardMetadataFormatSupported()) {
        throw new Error("Test failure: Missing metadata");
    }
    Element root = (Element) meta.
            getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);

    // Test getElementsByTagName("*")
    if (root.getElementsByTagName("*").getLength() == 0) {
        throw new RuntimeException("getElementsByTagName(\"*\") returns"
                + " nothing");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:GetElementsByTagNameTest.java

示例7: main

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    String fileName = "nomarkers.jpg";
    String sep = System.getProperty("file.separator");
    String dir = System.getProperty("test.src", ".");
    String filePath = dir+sep+fileName;
    System.out.println("Test file: " + filePath);
    File file = new File(filePath);
    ImageInputStream stream = ImageIO.createImageInputStream(file);
    Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);

    if(readers.hasNext()) {
        ImageReader reader = readers.next();
        reader.setInput(stream);
        IIOMetadata metadata = reader.getImageMetadata(0);

        IIOMetadataNode standardTree = (IIOMetadataNode)
            metadata.getAsTree
            (IIOMetadataFormatImpl.standardMetadataFormatName);
        IIOMetadataNode colorSpaceType = (IIOMetadataNode)
            standardTree.getElementsByTagName("ColorSpaceType").item(0);
        String colorSpaceName = colorSpaceType.getAttribute("name");
        if(colorSpaceName.equals("RGB"))
            throw new RuntimeException("Identified incorrect ColorSpace");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:JpegMetadataColorSpaceTest.java

示例8: testGetAsTree

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
public void testGetAsTree() {
    ImageWriteParam p = w.getDefaultWriteParam();
    IIOMetadata m =
        w.getDefaultImageMetadata(ImageTypeSpecifier.createFromBufferedImageType(type), p);

    String format = m.getNativeMetadataFormatName();
    System.out.println("native format: " + format);

    int count = 0;
    try {
        while (count < 100) {
            System.out.println(" test " + count++);
            m.getAsTree(format);
        }
    } catch (OutOfMemoryError e) {
        System.gc();
        throw new RuntimeException("Test failed. Number of performed operations: " + count, e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:UshortOutOfMemoryTest.java

示例9: paintToPng

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
/**
 * Paints this panel to a PNG image with specified resolution and width.
 * The image height is computed so that the image has the same aspect 
 * ratio as this panel.
 * @param dpi the image resolution, in dots per inch.
 * @param win the image width, in inches.
 * @param fileName the name of the file to contain the PNG image.
 * @throws IOException when unable to save to file.
 */
public void paintToPng(double dpi, double win, String fileName) 
  throws IOException 
{
  BufferedImage image = paintToImage((int)ceil(dpi*win));
  // The two lines below are simple, but do not write resolution info to 
  // the PNG file. We want that info, especially for high-res images.
  //File file = new File(fileName);
  //ImageIO.write(image,"png",file);
  Iterator<ImageWriter> i = ImageIO.getImageWritersBySuffix("png");
  if (!i.hasNext())
    throw new IOException("cannot get a PNG image writer");
  ImageWriter iw = i.next();
  FileOutputStream fos = new FileOutputStream(fileName);
  ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
  iw.setOutput(ios);
  ImageWriteParam iwp = iw.getDefaultWriteParam();
  ImageTypeSpecifier its = new ImageTypeSpecifier(image);
  IIOMetadata imd = iw.getDefaultImageMetadata(its,iwp);
  String format = "javax_imageio_png_1.0";
  IIOMetadataNode tree = (IIOMetadataNode)imd.getAsTree(format);
  IIOMetadataNode node = new IIOMetadataNode("pHYs");
  String dpm = Integer.toString((int)ceil(dpi/0.0254));
  node.setAttribute("pixelsPerUnitXAxis",dpm);
  node.setAttribute("pixelsPerUnitYAxis",dpm);
  node.setAttribute("unitSpecifier","meter");
  tree.appendChild(node);
  imd.setFromTree(format,tree);
  iw.write(new IIOImage(image,null,imd));
  ios.flush();
  ios.close();
  fos.flush();
  fos.close();
  iw.dispose();
}
 
开发者ID:MinesJTK,项目名称:jtk,代码行数:44,代码来源:IPanel.java

示例10: convertMetadata

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
/**
 * Merges <code>inData</code> into <code>outData</code>. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:GIFImageWriter.java

示例11: checkColorDepth

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
private void checkColorDepth() {
    IIOMetadata dst = iio_dst.getMetadata();

    Node data = dst.getAsTree("javax_imageio_bmp_1.0");

    Node n = data.getFirstChild();

    while (n != null && !("BitsPerPixel".equals(n.getNodeName()))) {
        System.out.println("Node " + n.getNodeName());
        n = n.getNextSibling();
    }
    if (n == null) {
        throw new RuntimeException("No BitsPerSample node!");
    }

    int bpp = 0;
    String value = n.getNodeValue();
    System.out.println("value = " + value);
    try {
        bpp = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        throw new RuntimeException("Wrong bpp value: " + value, e);
    }

    if (bpp != this.expectedColorDepth) {
        throw new RuntimeException("Wrong color depth: " + bpp +
                " (should be " + this.expectedColorDepth + ")");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:NoExtraBytesTest.java

示例12: writeTo

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
private static void writeTo(File f, ITXtTest t) {
    BufferedImage src = createBufferedImage();
    try (ImageOutputStream imageOutputStream =
            ImageIO.createImageOutputStream(f)) {

        ImageTypeSpecifier imageTypeSpecifier =
            new ImageTypeSpecifier(src);
        ImageWriter imageWriter =
            ImageIO.getImageWritersByFormatName("PNG").next();

        imageWriter.setOutput(imageOutputStream);

        IIOMetadata m =
            imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);

        String format = m.getNativeMetadataFormatName();
        Node root = m.getAsTree(format);

        IIOMetadataNode iTXt = t.getNode();
        root.appendChild(iTXt);
        m.setFromTree(format, root);

        imageWriter.write(new IIOImage(src, null, m));
        System.out.println("Writing done.");
    } catch (Throwable e) {
        throw new RuntimeException("Writing test failed.", e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ITXtTest.java

示例13: writeTo

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
private static void writeTo(File f, ITXtTest t) {
    BufferedImage src = createBufferedImage();
    try {
        ImageOutputStream imageOutputStream =
            ImageIO.createImageOutputStream(f);

        ImageTypeSpecifier imageTypeSpecifier =
            new ImageTypeSpecifier(src);
        ImageWriter imageWriter =
            ImageIO.getImageWritersByFormatName("PNG").next();

        imageWriter.setOutput(imageOutputStream);

        IIOMetadata m =
            imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);

        String format = m.getNativeMetadataFormatName();
        Node root = m.getAsTree(format);

        IIOMetadataNode iTXt = t.getNode();
        root.appendChild(iTXt);
        m.setFromTree(format, root);

        imageWriter.write(new IIOImage(src, null, m));
        imageOutputStream.close();
        System.out.println("Writing done.");
    } catch (Throwable e) {
        throw new RuntimeException("Writing test failed.", e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:ITXtTest.java

示例14: convertMetadata

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
/**
 * Merges {@code inData} into {@code outData}. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:GIFImageWriter.java

示例15: main

import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    ImageWriter iw =
        (ImageWriter)ImageIO.getImageWritersByFormatName("jpeg").next();

    ImageTypeSpecifier type =
        ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);

    ImageOutputStream ios =
        ImageIO.createImageOutputStream(new File("MergeTreeTest.jpeg"));
    iw.setOutput(ios);

    IIOMetadata meta = iw.getDefaultImageMetadata(type, null);

    boolean isFailed = false;

    String[] fmts = meta.getMetadataFormatNames();
    for (int i=0; i<fmts.length; i++) {
        System.out.print("Format: " + fmts[i] + " ... ");
        Node root = meta.getAsTree(fmts[i]);
        try {
            meta.mergeTree(fmts[i], root);
        } catch (NullPointerException e) {
            throw new RuntimeException("Test failed for format " + fmts[i], e);
        }
        System.out.println("PASSED");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:MergeTreeTest.java


注:本文中的javax.imageio.metadata.IIOMetadata.getAsTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。