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


Java ImageTypeSpecifier.createFromRenderedImage方法代码示例

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


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

示例1: main

import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
public static void main(String[] args) {
    for (int i = 0; i < types.length; i++) {
        BufferedImage img = new BufferedImage(32, 32, types[i]);

        ImageTypeSpecifier spec =
            ImageTypeSpecifier.createFromRenderedImage(img);

        Iterator writers = ImageIO.getImageWriters(spec, "png");

        if (!writers.hasNext()) {
            throw new RuntimeException("Test failed: " +
                                       "no PNG writer found for type " +
                                       typeNames[i]);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:CanEncodeShort.java

示例2: main

import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
public static void main(String[] args) {
    BufferedImage img = new BufferedImage(32, 32,
                                          BufferedImage.TYPE_BYTE_INDEXED);

    ImageTypeSpecifier spec =
        ImageTypeSpecifier.createFromRenderedImage(img);

    Iterator writers = ImageIO.getImageWriters(spec, "jpeg");

    if (!writers.hasNext()) {
        throw new RuntimeException("Test failed: " +
                                   "no JPEG writer found for " +
                                   "image with IndexColorModel");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:CanEncodeIndexed.java

示例3: main

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

示例4: createTestPng

import javax.imageio.ImageTypeSpecifier; //导入方法依赖的package包/类
private static byte[] createTestPng() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    BufferedImage img = createTestImage();

    try {
        ImageOutputStream ios = ImageIO.createImageOutputStream(baos);

        ImageWriter w = ImageIO.getImageWritersByFormatName("PNG").next();

        w.setOutput(ios);

        ImageWriteParam p = w.getDefaultWriteParam();

        ImageTypeSpecifier t = ImageTypeSpecifier.createFromRenderedImage(img);

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

        String nativeMetadataFormat = m.getNativeMetadataFormatName();

        Node root = m.getAsTree(nativeMetadataFormat);

        IIOMetadataNode textEntry = new IIOMetadataNode("tEXtEntry");
        textEntry.setAttribute("keyword", "comment");
        textEntry.setAttribute("value", "This is a test image for JDK-6945174");

        IIOMetadataNode text = new IIOMetadataNode("tEXt");
        text.appendChild(textEntry);

        root.appendChild(text);

        m.mergeTree(nativeMetadataFormat, root);

        IIOImage iio_img = new IIOImage(img, null, m);

        w.write(iio_img);

        w.dispose();
        ios.flush();
        ios.close();
    } catch (IOException e) {
        throw new RuntimeException("Test failed.", e);
    }

    baos.flush();

    byte[] data = baos.toByteArray();

    adjustCommentLength(Integer.MAX_VALUE + 0x1000, data);

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


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