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


Java ImageWriteParam.setCompressionType方法代码示例

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


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

示例1: getImageWriteParam

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
private ImageWriteParam getImageWriteParam(ImageWriter writer, String value) {
    ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();
    imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    imageWriteParam.setCompressionType(value);
    return imageWriteParam;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:BMPSubsamplingTest.java

示例2: doTest

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
public void doTest(int type) throws IOException {
    BufferedImage src = getTestImage(type);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);

    ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
    writer.setOutput(ios);

    ImageWriteParam wparam = writer.getDefaultWriteParam();
    wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    switch(type) {
        case TEST_RLE8:
            wparam.setCompressionType("BI_RLE8");
            break;
        case TEST_RLE4:
            wparam.setCompressionType("BI_RLE4");
            break;
        default:
            throw new IllegalArgumentException("Wrong test type: " + type);
    }

    writer.write(null, new IIOImage(src, null, null), wparam);

    ios.close();
    baos.close();

    // read result
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

    BufferedImage dst = ImageIO.read(bais);

    checkResult(src, dst);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:RLECompressionTest.java

示例3: doTest

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
public void doTest() {
    try {
        System.out.println("Progress test for " + compression_type);
        BufferedImage bi = new BufferedImage(20, 300, BufferedImage.TYPE_INT_RGB);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageOutputStream ios = ImageIO.createImageOutputStream(baos);

        Iterator iter = ImageIO.getImageWritersByFormatName(format);
        if (!iter.hasNext()) {
            throw new RuntimeException("No available writer for " + format);
        }
        ImageWriter writer = (ImageWriter)iter.next();

        writer.setOutput(ios);
        writer.addIIOWriteProgressListener(listener);

        IIOImage iio_img = new IIOImage(bi, null, null);

        ImageWriteParam param = writer.getDefaultWriteParam();

        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionType(compression_type);


        writer.write(null, iio_img, param);

        if (!listener.isTestPassed) {
            throw new RuntimeException("Test for " + compression_type + " does not finish correctly!");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:WriteProgressListenerTest.java

示例4: prepareWriteParam

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
protected ImageWriteParam prepareWriteParam(BufferedImage src) {
    ImageWriteParam wparam = writer.getDefaultWriteParam();
    wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    wparam.setCompressionType("BI_BITFIELDS");

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

示例5: doTest

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
private static void doTest(BufferedImage src,
                           String compressionType,
                           int compressionMode) throws IOException
{

    ImageWriter iw =  (ImageWriter)ImageIO.getImageWritersBySuffix("bmp").next();
    if (iw == null) {
        throw new RuntimeException("No available writer. Test failed.");
    }

    IIOImage iioImg = new IIOImage(src, null, null);
    ImageWriteParam param = iw.getDefaultWriteParam();


    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    iw.setOutput(ios);

    System.out.println("Compression Type is " + compressionType);
    System.out.println("Compression Mode is " + compressionMode);

    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionType(compressionType);
    if (compressionMode != ImageWriteParam.MODE_EXPLICIT) {
        param.setCompressionMode(compressionMode);
    }
    try {
        iw.write(null, iioImg, param);
    } catch (IOException e) {
        int bpp = src.getColorModel().getPixelSize();
        if (compressionMode == ImageWriteParam.MODE_EXPLICIT) {
            if ((compressionType.equals("BI_RLE4") && bpp != 4)
                || (compressionType.equals("BI_RLE8") && bpp != 8))
            {
                System.out.println("Can not encode "+ bpp+ "bpp image as"
                                  + compressionType);
                return;
            } else {
                throw new RuntimeException("Unable to encode "
                                           + bpp + "bpp image as "
                                           + compressionType
                                           + ". Test failed");
            }
        }
    }
    baos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ImageInputStream iis = ImageIO.createImageInputStream(bais);

    BufferedImage dst = ImageIO.read(iis);

    int w = src.getWidth();
    int h = src.getHeight();

    Object dstPixel = dst.getRaster().getDataElements(w/2, h/2, null);
    Object srcPixel = src.getRaster().getDataElements(w/2, h/2, null);

    if ( (src.getColorModel().getRed(srcPixel)
          != dst.getColorModel().getRed(dstPixel))
         || (src.getColorModel().getGreen(srcPixel)
             != dst.getColorModel().getGreen(dstPixel))
         || (src.getColorModel().getBlue(srcPixel)
             != dst.getColorModel().getBlue(dstPixel))
         || (src.getColorModel().getAlpha(srcPixel)
             != dst.getColorModel().getAlpha(dstPixel)) ) {

        showPixel(src, w/2, h/2);
        showPixel(dst, w/2, h/2);

        throw new RuntimeException(
            "Colors are different: " +
            Integer.toHexString(src.getColorModel().getRGB(srcPixel))
            + " and " +
            Integer.toHexString(dst.getColorModel().getRGB(dstPixel)));
    }

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

示例6: doTest

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
private static void doTest(String compression) {
    try {
        BufferedImage img = createTestImage();

        ImageWriter iw = (ImageWriter)
            ImageIO.getImageWritersByFormatName("bmp").next();
        if (iw == null) {
            throw new RuntimeException("No writers for bmp format."
                                       + " Test failed.");
        }


        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        iw.setOutput(ImageIO.createImageOutputStream(baos));
        ImageWriteParam param = iw.getDefaultWriteParam();
        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionType(compression);

        iw.write(null, new IIOImage(img, null, null), param);
        baos.close();

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

        ImageReader ir = (ImageReader)
            ImageIO.getImageReadersByFormatName("bmp").next();
        if (ir == null) {
            throw new RuntimeException("No readers for bmp format."
                                       + " Test failed.");
        }

        IIOReadUpdateAdapter updateAdapter = new IIOReadUpdateAdapter();
        IIOReadProgressAdapter progressAdapter = new IIOReadProgressAdapter();
        ir.addIIOReadProgressListener(progressAdapter);
        ir.addIIOReadUpdateListener(updateAdapter);
        ir.setInput(ImageIO.createImageInputStream(bais));
        BufferedImage dst = ir.read(0);

        progressAdapter.checkResults();

        if (!updateAdapter.isImageUpdateUsed) {
            throw new RuntimeException("imageUpdate was not used."
                                       + " Test failed.");
        }
    } catch(IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Test failed");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:ReaderListenersTest.java

示例7: prepareWriteParam

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
protected ImageWriteParam prepareWriteParam(String compression) {
    ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();
    imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    imageWriteParam.setCompressionType(compression);
    return imageWriteParam;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:EmbeddedFormatTest.java

示例8: test

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
private static void test() throws IOException {
    int failures = 0;

    for (int imageType : typeToCompression.keySet()) {
        BufferedImage image = new BufferedImage(WIDTH, HEIGHT, imageType);
        System.out.println("Image: " + image.toString());

        for (String compression : typeToCompression.get(imageType)) {
            System.out.println("Compression: "
                    + (compression == null ? "None" : compression));
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            ImageOutputStream ios = new MemoryCacheImageOutputStream(output);
            ImageWriter writer =
                    ImageIO.getImageWritersByFormatName("TIFF").next();
            ImageWriteParam wparam = writer.getDefaultWriteParam();
            if (compression == null) {
                wparam.setCompressionMode(ImageWriteParam.MODE_DEFAULT);
            } else {
                wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                wparam.setCompressionType(compression);
            }
            writer.setOutput(ios);
            writer.write(null, new IIOImage(image, null, null), wparam);
            ios.flush();

            ImageReader reader =
                    ImageIO.getImageReadersByFormatName("TIFF").next();
            ByteArrayInputStream input
                    = new ByteArrayInputStream(output.toByteArray());
            ImageInputStream iis = new MemoryCacheImageInputStream(input);
            iis.mark();

            TIFFImageReadParam rparam = new TIFFImageReadParam();
            rparam.removeAllowedTagSet(BaselineTIFFTagSet.getInstance());

            reader.setInput(iis, false, false);
            BufferedImage resultFalse = reader.read(0, rparam);
            if (resultFalse.getWidth() != WIDTH
                    || resultFalse.getHeight() != HEIGHT) {
                System.err.printf("Read image dimensions != %d x %d%n",
                        WIDTH, HEIGHT);
                failures++;
            } else {
                System.out.println("ignoreMetadata == false test passed");
            }

            iis.reset();
            reader.setInput(iis, false, true);
            BufferedImage resultTrue;
            try {
                resultTrue = reader.read(0, rparam);
                if (resultTrue.getWidth() != WIDTH
                        || resultTrue.getHeight() != HEIGHT) {
                    System.err.printf("Read image dimensions != %d x %d%n",
                            WIDTH, HEIGHT);
                    failures++;
                } else {
                    System.out.println("ignoreMetadata == true test passed");
                }
            } catch (Exception e) {
                e.printStackTrace();
                failures++;
            }
        }
    }

    if (failures != 0) {
        throw new RuntimeException("Test failed with "
                + failures + " errors!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:72,代码来源:ReadWithoutBaselineTagSet.java


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