javax.imageio.ImageWriteParam Java Examples

The following examples show how to use javax.imageio.ImageWriteParam. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DestTypeTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public byte[] writeTest(BufferedImage bi,
                        ImageWriteParam p,
                        IIOMetadata m) throws IOException {
    ByteArrayOutputStream baos =
        new ByteArrayOutputStream();

    // write test image as jpeg
    ImageOutputStream ios =
        ImageIO.createImageOutputStream(baos);
    w.setOutput(ios);
    w.write(null,
            new IIOImage(bi, null, m),
            p);
    ios.close();
    return baos.toByteArray();
}
 
Example #2
Source File: WriteMetadataTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: GIFImageWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void writeToSequence(IIOImage image, ImageWriteParam param)
  throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    if (image.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }
    if (!isWritingSequence) {
        throw new IllegalStateException("prepareWriteSequence() was not invoked!");
    }

    write(!wroteSequenceHeader, false, theStreamMetadata,
          image, param);

    if (!wroteSequenceHeader) {
        wroteSequenceHeader = true;
    }

    this.imageIndex++;
}
 
Example #4
Source File: GIFImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public void writeToSequence(IIOImage image, ImageWriteParam param)
  throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    if (image.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }
    if (!isWritingSequence) {
        throw new IllegalStateException("prepareWriteSequence() was not invoked!");
    }

    write(!wroteSequenceHeader, false, theStreamMetadata,
          image, param);

    if (!wroteSequenceHeader) {
        wroteSequenceHeader = true;
    }

    this.imageIndex++;
}
 
Example #5
Source File: GIFImageWriter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void writeToSequence(IIOImage image, ImageWriteParam param)
  throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    if (image.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }
    if (!isWritingSequence) {
        throw new IllegalStateException("prepareWriteSequence() was not invoked!");
    }

    write(!wroteSequenceHeader, false, theStreamMetadata,
          image, param);

    if (!wroteSequenceHeader) {
        wroteSequenceHeader = true;
    }

    this.imageIndex++;
}
 
Example #6
Source File: JPEGImageWriter.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private boolean jfifOK(ImageTypeSpecifier imageType,
                       ImageWriteParam param,
                       IIOMetadata streamMetadata,
                       IIOMetadata imageMetadata) {
    // If the image type and metadata are JFIF compatible, return true
    if ((imageType != null) &&
        (!JPEG.isJFIFcompliant(imageType, true))) {
        return false;
    }
    if (imageMetadata != null) {
        JPEGMetadata metadata = null;
        if (imageMetadata instanceof JPEGMetadata) {
            metadata = (JPEGMetadata) imageMetadata;
        } else {
            metadata = (JPEGMetadata)convertImageMetadata(imageMetadata,
                                                          imageType,
                                                          param);
        }
        // metadata must have a jfif node
        if (metadata.findMarkerSegment
            (JFIFMarkerSegment.class, true) == null){
            return false;
        }
    }
    return true;
}
 
Example #7
Source File: ImageFileWriters.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static ImageWriteParam getWriterParam(ImageAttributes attributes,
        ImageWriter writer) {
    try {
        ImageWriteParam param = writer.getDefaultWriteParam();
        if (param.canWriteCompressed()) {
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            if (attributes != null && attributes.getCompressionType() != null) {
                param.setCompressionType(attributes.getCompressionType());
            } else {
                String[] compressionTypes = param.getCompressionTypes();
                if (compressionTypes != null) {
                    param.setCompressionType(compressionTypes[0]);
                }
            }
            if (attributes != null && attributes.getQuality() > 0) {
                param.setCompressionQuality(attributes.getQuality() / 100.0f);
            } else {
                param.setCompressionQuality(1.0f);
            }
        }
        return param;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example #8
Source File: RleEncodingTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void encodeRLE8Test() throws IOException {
    // create 8bpp image
    byte[] r = new byte[256];
    r[0] = (byte)0xff;
    byte[] g = new byte[256];
    g[1] = (byte)0xff;
    byte[] b = new byte[256];
    b[2] = (byte)0xff;
    IndexColorModel icm = new IndexColorModel(8, 256, r, g, b);

    BufferedImage bimg = new BufferedImage(100, 100,
                                           BufferedImage.TYPE_BYTE_INDEXED,
                                           icm);
    Graphics gr = bimg.getGraphics();
    gr.setColor(Color.green);
    gr.fillRect(0, 0, 100, 100);

    doTest(bimg, "BI_RLE8", ImageWriteParam.MODE_EXPLICIT);
}
 
Example #9
Source File: LUTCompareTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static Image createTestImage() throws IOException  {
    BufferedImage frame1 = createFrame(new int[] { 0xffff0000, 0xffff0000 });
    BufferedImage frame2 = createFrame(new int[] { 0xff0000ff, 0xffff0000 });

    ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(new File("lut_test.gif"));
    ImageWriteParam param = writer.getDefaultWriteParam();
    writer.setOutput(ios);
    writer.prepareWriteSequence(null);
    writer.writeToSequence(new IIOImage(frame1, null, null), param);
    writer.writeToSequence(new IIOImage(frame2, null, null), param);
    writer.endWriteSequence();
    writer.reset();
    writer.dispose();

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

    return Toolkit.getDefaultToolkit().createImage("lut_test.gif");
}
 
Example #10
Source File: JPEGImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private boolean jfifOK(ImageTypeSpecifier imageType,
                       ImageWriteParam param,
                       IIOMetadata streamMetadata,
                       IIOMetadata imageMetadata) {
    // If the image type and metadata are JFIF compatible, return true
    if ((imageType != null) &&
        (!JPEG.isJFIFcompliant(imageType, true))) {
        return false;
    }
    if (imageMetadata != null) {
        JPEGMetadata metadata = null;
        if (imageMetadata instanceof JPEGMetadata) {
            metadata = (JPEGMetadata) imageMetadata;
        } else {
            metadata = (JPEGMetadata)convertImageMetadata(imageMetadata,
                                                          imageType,
                                                          param);
        }
        // metadata must have a jfif node
        if (metadata.findMarkerSegment
            (JFIFMarkerSegment.class, true) == null){
            return false;
        }
    }
    return true;
}
 
Example #11
Source File: ShortHistogramTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected File writeImageWithHist(BufferedImage bi) throws IOException {
    File f = File.createTempFile("hist_", ".png", new File("."));

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

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

    ImageWriteParam param = writer.getDefaultWriteParam();
    ImageTypeSpecifier type = new ImageTypeSpecifier(bi);

    IIOMetadata imgMetadata = writer.getDefaultImageMetadata(type, param);

    /* add hIST node to image metadata */
    imgMetadata = upgradeMetadata(imgMetadata, bi);

    IIOImage iio_img = new IIOImage(bi,
                                    null, // no thumbnails
                                    imgMetadata);

    writer.write(iio_img);
    ios.flush();
    ios.close();
    return f;
}
 
Example #12
Source File: GIFImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void writeToSequence(IIOImage image, ImageWriteParam param)
  throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    if (image.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }
    if (!isWritingSequence) {
        throw new IllegalStateException("prepareWriteSequence() was not invoked!");
    }

    write(!wroteSequenceHeader, false, theStreamMetadata,
          image, param);

    if (!wroteSequenceHeader) {
        wroteSequenceHeader = true;
    }

    this.imageIndex++;
}
 
Example #13
Source File: GIFImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void write(IIOMetadata sm,
                  IIOImage iioimage,
                  ImageWriteParam p) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (iioimage == null) {
        throw new IllegalArgumentException("iioimage == null!");
    }
    if (iioimage.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }

    resetLocal();

    GIFWritableStreamMetadata streamMetadata;
    if (sm == null) {
        streamMetadata =
            (GIFWritableStreamMetadata)getDefaultStreamMetadata(p);
    } else {
        streamMetadata =
            (GIFWritableStreamMetadata)convertStreamMetadata(sm, p);
    }

    write(true, true, streamMetadata, iioimage, p);
}
 
Example #14
Source File: OpaquePNGToGIFTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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();
    }
}
 
Example #15
Source File: GIFImageWriter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public void write(IIOMetadata sm,
                  IIOImage iioimage,
                  ImageWriteParam p) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (iioimage == null) {
        throw new IllegalArgumentException("iioimage == null!");
    }
    if (iioimage.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }

    resetLocal();

    GIFWritableStreamMetadata streamMetadata;
    if (sm == null) {
        streamMetadata =
            (GIFWritableStreamMetadata)getDefaultStreamMetadata(p);
    } else {
        streamMetadata =
            (GIFWritableStreamMetadata)convertStreamMetadata(sm, p);
    }

    write(true, true, streamMetadata, iioimage, p);
}
 
Example #16
Source File: RleEncodingTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    try {
        int mode = ImageWriteParam.MODE_EXPLICIT;
        String type = "BI_RLE4";
        doTest(type, mode);

        type = "BI_RLE8";
        doTest(type, mode);

        mode = ImageWriteParam.MODE_DEFAULT;
        type = "BI_RLE4";
        doTest(type, mode);

        type = "BI_RLE8";
        doTest(type, mode);

        System.out.println("Test 4bpp image.");
        encodeRLE4Test();

        System.out.println("Test 8bpp image.");
        encodeRLE8Test();
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Unexpected exception. Test failed");
    }
}
 
Example #17
Source File: JPEGImageWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public int getNumThumbnailsSupported(ImageTypeSpecifier imageType,
                                     ImageWriteParam param,
                                     IIOMetadata streamMetadata,
                                     IIOMetadata imageMetadata) {
    if (jfifOK(imageType, param, streamMetadata, imageMetadata)) {
        return Integer.MAX_VALUE;
    }
    return 0;
}
 
Example #18
Source File: JPEGImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Dimension[] getPreferredThumbnailSizes(ImageTypeSpecifier imageType,
                                              ImageWriteParam param,
                                              IIOMetadata streamMetadata,
                                              IIOMetadata imageMetadata) {
    if (jfifOK(imageType, param, streamMetadata, imageMetadata)) {
        return (Dimension [])preferredThumbSizes.clone();
    }
    return null;
}
 
Example #19
Source File: EncodeSubImageTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void write(File f, boolean subsample) throws IOException {
    ImageOutputStream ios = ImageIO.createImageOutputStream(f);

    writer.setOutput(ios);
    ImageWriteParam p = writer.getDefaultWriteParam();
    if (subsample) {
        p.setSourceSubsampling(subSampleX, subSampleY, 0, 0);
    }
    writer.write(null, new IIOImage(img, null, null), p);
    ios.close();
    writer.reset();
}
 
Example #20
Source File: GraphicsDevice.java    From basicv2 with The Unlicense 5 votes vote down vote up
/**
 * Saves the current image into a PNG file.
 * 
 * @param machine the machine
 * @param name    the name of the target file
 */
public void save(Machine machine, String name) {
	try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(name));
			ImageOutputStream ios = ImageIO.createImageOutputStream(bos)) {
		Iterator<ImageWriter> itty = ImageIO.getImageWritersBySuffix("png");
		if (itty.hasNext()) {
			ImageWriter iw = (ImageWriter) itty.next();
			ImageWriteParam iwp = iw.getDefaultWriteParam();
			iw.setOutput(ios);
			iw.write(null, new IIOImage((RenderedImage) getScreen(), null, null), iwp);
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example #21
Source File: JPEGImageWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata
    getDefaultImageMetadata(ImageTypeSpecifier imageType,
                            ImageWriteParam param) {
    setThreadLock();
    try {
        return new JPEGMetadata(imageType, param, this);
    } finally {
        clearThreadLock();
    }
}
 
Example #22
Source File: RGBImageTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
    }

}
 
Example #23
Source File: GIFImageWriter.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Creates a default image metadata object and merges in the
 * supplied metadata.
 */
public IIOMetadata convertImageMetadata(IIOMetadata inData,
                                        ImageTypeSpecifier imageType,
                                        ImageWriteParam param) {
    if (inData == null) {
        throw new IllegalArgumentException("inData == null!");
    }
    if (imageType == null) {
        throw new IllegalArgumentException("imageType == null!");
    }

    GIFWritableImageMetadata im =
        (GIFWritableImageMetadata)getDefaultImageMetadata(imageType,
                                                          param);

    // Save interlace flag state.

    boolean isProgressive = im.interlaceFlag;

    convertMetadata(IMAGE_METADATA_NAME, inData, im);

    // Undo change to interlace flag if not MODE_COPY_FROM_METADATA.

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) {
        im.interlaceFlag = isProgressive;
    }

    return im;
}
 
Example #24
Source File: RLECompressionTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #25
Source File: ImageUtil.java    From minifierbeans with Apache License 2.0 5 votes vote down vote up
public void compressJPG(String inputFilePath, String outputFilePath, String fileType) {
    InputOutput io = IOProvider.getDefault().getIO(Bundle.CTL_Base64Encode(), false);
    try {
        File imageFile = new File(inputFilePath);
        File compressedImageFile = new File(outputFilePath);

        InputStream is = new FileInputStream(imageFile);
        OutputStream os = new FileOutputStream(compressedImageFile);
        float quality = 0.5f;
        
        // create a BufferedImage as the result of decoding the supplied InputStream
        BufferedImage image = ImageIO.read(is);
        
        // get all image writers for JPG format
        Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(fileType);

        if (!writers.hasNext()) {
            throw new IllegalStateException("No writers found");
        }
        
        ImageWriter writer = writers.next();
        ImageOutputStream ios = ImageIO.createImageOutputStream(os);
        writer.setOutput(ios);
        ImageWriteParam param = writer.getDefaultWriteParam();

        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionQuality(quality);
        
        // appends a complete image stream containing a single image and
        //associated stream and image metadata and thumbnails to the output
        writer.write(null, new IIOImage(image, null, null), param);

        is.close();
        os.close();
        ios.close();
        writer.dispose();
    } catch (IOException ex) {
        io.getOut().println("Exception: " + ex.toString());
    }
}
 
Example #26
Source File: JPEGImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Dimension[] getPreferredThumbnailSizes(ImageTypeSpecifier imageType,
                                              ImageWriteParam param,
                                              IIOMetadata streamMetadata,
                                              IIOMetadata imageMetadata) {
    if (jfifOK(imageType, param, streamMetadata, imageMetadata)) {
        return preferredThumbSizes.clone();
    }
    return null;
}
 
Example #27
Source File: Jpeg2000WriteTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
@Test
    public void lossyWrite() throws Exception {
        File f = File.createTempFile("test-jpeg2000-lossy", ".jp2");
        f.deleteOnExit();
        Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jp2");
        assertTrue(writers.hasNext());
        ImageWriter writer = writers.next();
        J2KImageWriteParam writeParams = (J2KImageWriteParam) writer.getDefaultWriteParam();
        writeParams.setLossless(false);
        writeParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        writeParams.setCompressionType("JPEG2000");
//        writeParams.setFilter(J2KImageWriteParam.FILTER_97);


        
        writeParams.setCompressionQuality(0.0f);
        writeParams.setEncodingRate(0.5f);
        ImageOutputStream ios = ImageIO.createImageOutputStream(f);
        writer.setOutput(ios);
        writer.write(null, new IIOImage(image, null, null), writeParams);
        writer.dispose();
        ios.close();
        assertTrue("Expected file size < 1MB", f.length() < 128*1024);
        //System.out.println(f.length());
        BufferedImage read = ImageIO.read(f);
        assertEquals(SIZE, read.getWidth());
    }
 
Example #28
Source File: PNGImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata convertImageMetadata(IIOMetadata inData,
                                        ImageTypeSpecifier imageType,
                                        ImageWriteParam param) {
    // TODO - deal with imageType
    if (inData instanceof PNGMetadata) {
        return (PNGMetadata)((PNGMetadata)inData).clone();
    } else {
        return new PNGMetadata(inData);
    }
}
 
Example #29
Source File: JPEGImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) {
    setThreadLock();
    try {
        return new JPEGMetadata(param, this);
    } finally {
        clearThreadLock();
    }
}
 
Example #30
Source File: BMPImageWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}