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


Java ImageWriter.getDefaultStreamMetadata方法代码示例

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


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

示例1: test

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void test(final ImageWriter writer) throws Exception {
    final File file = File.createTempFile("temp", ".img");
    file.deleteOnExit();
    final FileOutputStream fos = new FileOutputStream(file);
    final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
    writer.setOutput(ios);
    final IIOMetadata data = writer.getDefaultStreamMetadata(null);

    if (writer.canWriteSequence()) {
        writer.prepareWriteSequence(data);
    } else {
        try {
            writer.prepareWriteSequence(data);
            throw new RuntimeException(
                    "UnsupportedOperationException was not thrown");
        } catch (final UnsupportedOperationException ignored) {
            // expected
        }
    }
    writer.dispose();
    ios.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:CanWriteSequence.java

示例2: createAnimatedImage

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public void createAnimatedImage(BufferedImage bi, IIOMetadata metadata,
        ImageWriter writer, File outputFile) {
    try {

        fos = new FileOutputStream(outputFile);
        ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
        System.out.println(ios);
        writer.setOutput(ios);

        ImageWriteParam param = writer.getDefaultWriteParam();
        IIOMetadata streamData = writer.getDefaultStreamMetadata(param);

        writer.prepareWriteSequence(streamData);
        ImageTypeSpecifier specify = new ImageTypeSpecifier(bi);
        IIOMetadata imgData = writer.convertImageMetadata(
                (IIOMetadata) metadata, specify, param);
        GIFImageMetadata gifData = setAnimationProperties(imgData);
        IIOImage iim = new IIOImage(bi, null, gifData);
        param.setProgressiveMode(param.MODE_DISABLED);
        writer.writeToSequence(iim, param);
        writer.endWriteSequence();
        ios.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:OpaquePNGToGIFTest.java

示例3: main

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

    ImageWriteParam param = writer.getDefaultWriteParam();

    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param);

    boolean gotException = false;
    try {
        writer.prepareWriteSequence(streamMetadata);
    } catch (IllegalStateException e) {
        gotException = true;
        System.out.println("Test passed.");
        e.printStackTrace(System.out);
    }

    if (!gotException) {
        throw new RuntimeException("Test failed.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:PrepareWriteSequenceTest.java

示例4: main

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) {
    ImageWriter w = ImageIO.getImageWritersByFormatName(format).next();
    if (w == null) {
        throw new RuntimeException("No available writers for format " + format);
    }
    ImageWriteParam p = w.getDefaultWriteParam();

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

    IIOMetadata m = w.getDefaultImageMetadata(t, p);
    System.out.println("Default image metadata is " + m);
    testWritableMetadata(m);

    IIOMetadata sm = w.getDefaultStreamMetadata(p);
    System.out.println("Default stream metadata is " + sm);
    testWritableMetadata(sm);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:WriteMetadataTest.java

示例5: doTest

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
protected void doTest() throws IOException {
    BufferedImage biSrc = getSrc();

    ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    writer.setOutput(ios);

    ImageWriteParam writeParam = writer.getDefaultWriteParam();
    IIOMetadata imageMetadata =
        writer.getDefaultImageMetadata(new ImageTypeSpecifier(biSrc), writeParam);

    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(writeParam);

    IIOImage iioImg = new IIOImage(biSrc, null, imageMetadata);
    writer.write(streamMetadata, iioImg, writeParam);
    ios.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    ImageReader reader = ImageIO.getImageReader(writer);
    reader.setInput(iis);
    BufferedImage dst = reader.read(0);

    // do test
    int x = dx / 2;
    int y = height / 2;

    for (int i = 0; i < usedColors.length; i++) {
        int dstRgb = dst.getRGB(x, y);
        System.out.println("dstColor: " + Integer.toHexString(dstRgb));
        int srcRgb = usedColors[i].getRGB();
        System.out.println("srcColor: " + Integer.toHexString(srcRgb));
        if (dstRgb != srcRgb) {
            throw new RuntimeException("wrong color " + i + ": " + Integer.toHexString(dstRgb));
        }
        x += dx;
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:RGBImageTest.java

示例6: main

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
        AnimationTest t = new AnimationTest();
        t.initFrame();

        ImageWriter w = t.initWriter();

        ImageWriteParam p = w.getDefaultWriteParam();

        IIOMetadata streamMetadata = w.getDefaultStreamMetadata(p);

        w.prepareWriteSequence(streamMetadata);

        for (int i = 0; i < 50; i++) {
            BufferedImage f = t.createNextFrame();

            ImageTypeSpecifier type = new ImageTypeSpecifier(f);

            IIOMetadata m = w.getDefaultImageMetadata(type, p);

            w.writeToSequence(new IIOImage(f, null, m), p);
        }
        w.endWriteSequence();

        t.checkAnimation();
    } catch (Exception e) {
        throw new RuntimeException("Test failed.", e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:AnimationTest.java

示例7: test

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void test(final ImageWriter writer) throws Exception {
    try {
        file = File.createTempFile("temp", ".img");
        fos = new FileOutputStream(file);
        final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
        writer.setOutput(ios);
        final IIOMetadata data = writer.getDefaultStreamMetadata(null);

        if (writer.canWriteSequence()) {
            writer.prepareWriteSequence(data);
        } else {
            try {
                writer.prepareWriteSequence(data);
                throw new RuntimeException(
                        "UnsupportedOperationException was not thrown");
            } catch (final UnsupportedOperationException ignored) {
            // expected
            }
        }
    } finally {
        writer.dispose();
        if (file != null) {
            if (fos != null) {
                fos.close();
            }
            Files.delete(file.toPath());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:CanWriteSequence.java

示例8: test

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void test(String mimeType, boolean useStreamMeta,
                        String metaXml, String... boolXpaths)
    throws Exception
{
    BufferedImage img =
        new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
    ImageWriter iw = ImageIO.getImageWritersByMIMEType(mimeType).next();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
    iw.setOutput(ios);
    ImageWriteParam param = null;
    IIOMetadata streamMeta = iw.getDefaultStreamMetadata(param);
    IIOMetadata imageMeta =
        iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
    IIOMetadata meta = useStreamMeta ? streamMeta : imageMeta;
    Source src = new StreamSource(new StringReader(metaXml));
    DOMResult dst = new DOMResult();
    transform(src, dst);
    Document doc = (Document)dst.getNode();
    Element node = doc.getDocumentElement();
    String metaFormat = node.getNodeName();

    // Verify that the default metadata gets formatted correctly.
    verify(meta.getAsTree(metaFormat), boolXpaths, false);

    meta.mergeTree(metaFormat, node);

    // Verify that the merged metadata gets formatte correctly.
    verify(meta.getAsTree(metaFormat), boolXpaths, true);

    iw.write(streamMeta, new IIOImage(img, null, imageMeta), param);
    iw.dispose();
    ios.close();
    ImageReader ir = ImageIO.getImageReader(iw);
    byte[] bytes = os.toByteArray();
    if (bytes.length == 0)
        throw new AssertionError("Zero length image file");
    ByteArrayInputStream is = new ByteArrayInputStream(bytes);
    ImageInputStream iis = new MemoryCacheImageInputStream(is);
    ir.setInput(iis);
    if (useStreamMeta) meta = ir.getStreamMetadata();
    else meta = ir.getImageMetadata(0);

    // Verify again after writing and re-reading the image
    verify(meta.getAsTree(metaFormat), boolXpaths, true);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:47,代码来源:BooleanAttributes.java

示例9: doTest

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void doTest(boolean writeSequence) throws IOException {
    String format = "GIF";
    ImageWriter writer =
            ImageIO.getImageWritersByFormatName(format).next();
    if (writer == null) {
        throw new RuntimeException("No writer available for " + format);
    }

    BufferedImage img = createTestImage();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    writer.setOutput(ios);

    WriterReuseTest t = new WriterReuseTest();
    writer.addIIOWriteProgressListener(t);

    ImageWriteParam param = writer.getDefaultWriteParam();
    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param);
    IIOImage iioImg = new IIOImage(img, null, null);
    if (writeSequence) {
        writer.prepareWriteSequence(streamMetadata);
        writer.writeToSequence(iioImg, param);
    } else {
        writer.write(img);
    }

    if (!t.isWritingAborted || t.isWritingCompleted) {
        throw new RuntimeException("Test failed.");
    }
    t.reset();

    // next attempt after abort
    ImageOutputStream ios2 =
         ImageIO.createImageOutputStream(new ByteArrayOutputStream());
    writer.setOutput(ios2);
    if (writeSequence) {
        writer.writeToSequence(iioImg, param);
    } else {
        writer.write(img);
    }

    if (t.isWritingAborted || !t.isWritingCompleted) {
        throw new RuntimeException("Test failed.");
    }
    System.out.println("Test passed.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:WriterReuseTest.java

示例10: main

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    String format = "GIF";
    ImageWriter writer =
            ImageIO.getImageWritersByFormatName(format).next();
    if (writer == null) {
        throw new RuntimeException("No available writers for " + format);
    }

    BufferedImage img = createTestImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);

    ImageWriteParam p = writer.getDefaultWriteParam();
    ImageTypeSpecifier type =
        ImageTypeSpecifier.createFromRenderedImage(img);
    IIOMetadata inImageMetadata =
        writer.getDefaultImageMetadata(type, p);

    IIOMetadata inStreamMetadata = writer.getDefaultStreamMetadata(p);

    // write and read image
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    writer.setOutput(ios);

    writer.write(inStreamMetadata, new IIOImage(img, null, inImageMetadata), p);

    ios.flush();
    ios.close();

    // read result
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    ImageReader reader = ImageIO.getImageReader(writer);
    reader.setInput(iis);

    IIOMetadata outStreamMetadata = reader.getStreamMetadata();

    GIFStreamMetadata gifStreamMetadata = (GIFStreamMetadata)outStreamMetadata;

    if (gifStreamMetadata.logicalScreenWidth != img.getWidth() ||
            gifStreamMetadata.logicalScreenHeight != img.getHeight()) {
        throw new RuntimeException("Test failed due to wrong logical screen dimension.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:LogicalScreenDimensionTest.java


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