Java 8 ImageWriteParam - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ImageWriteParam class.

This code example shows how to use the following methods:canWriteCompressed, setCompressionMode, setCompressionQuality, setCompressionType
            writer = lookupImageWriterForFormat(imageFormat);
            ios = ImageIO.createImageOutputStream(os);
            writer.setOutput(ios);
            ImageWriteParam iwparam = getImageWriteParameters(writer);
 
            writer.write(null, new IIOImage(bimg, null, null), iwparam);
        } finally { 
            if (ios != null) {
                try { 
                    ios.flush();
                } catch (IOException e) {
                    // ignore 
                } 
                try { 
                    ios.close();
                } catch (IOException e) {
                    // ignore 
                } 
            } 
            if (writer != null) {

7
CodeRank
This code example shows how to use the following methods:setCompressionMode, setCompressionQuality
    // prepare output file 
    ios = ImageIO.createImageOutputStream(getFile());
    writer.setOutput(ios);
 
    // set the quality 
    param = new JPEGImageWriteParam(Locale.getDefault());
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
    param.setCompressionQuality(getQuality());
 
    // write the image 
    writer.write(null, new IIOImage(bi, null, null), param);
 
    // cleanup 
    ios.flush();
    writer.dispose();
    ios.close();    
  } 
   
  /** 
   * for testing only. 
7
CodeRank
This code example shows how to use the following methods:setCompressionMode, setCompressionQuality
This code example shows how to use the following methods:canWriteCompressed, setCompressionMode, setCompressionQuality
 
			writer = (ImageWriter) it.next();	
			ImageWriteParam iwp = writer.getDefaultWriteParam();
 
			// If compression is supported, then set the compression mode 
			if (iwp.canWriteCompressed()) {
				// Use explicit compression mode 
				iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
	 
				// Set compression quality, where 1 specifies minimum compression and maximum quality 
				iwp.setCompressionQuality(compressionQuality); // float between 0 and 1
			} 
			// Write the screen shot to file  
			output = new FileImageOutputStream(file);
			writer.setOutput(output);
			IIOImage image = new IIOImage(screenshot, null, null);
 
			writer.write(null, image, iwp);
		} catch (IOException e) {
			e.printStackTrace();

6
CodeRank
This code example shows how to use the following methods:setCompressionMode, setCompressionQuality
This code example shows how to use the following methods:setCompressionMode, setCompressionQuality
This code example shows how to use the following methods:setCompressionMode, setCompressionQuality
 
	public byte[] encode(RenderedImage image) throws java.io.IOException {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ImageWriter iw = ImageIO.getImageWritersByFormatName("jpeg").next();
		ImageWriteParam iwp = iw.getDefaultWriteParam();
		iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
		iwp.setCompressionQuality(_quality);
		ImageOutputStream ios = ImageIO.createImageOutputStream(os);
		iw.setOutput(ios);
		iw.write(null, new IIOImage(image, null, null), iwp);
		ios.flush();
		iw.dispose();
		ios.close();
		return os.toByteArray();
	} 
	/** Returns the quality of the image encoding. 
	 * It is a number between 0 and 1. The higher the value, 
	 * the better the output quality. 
	 * 
	 * <p>Default: 0.95f. 
6
CodeRank
This code example shows how to use the following methods:setCompressionMode, setCompressionQuality
This code example shows how to use the following methods:setCompressionMode, setCompressionQuality
        // TODO: make this more abstract - it should be smarter for more image 
        //       writer types (Ie. ask the writer what it supports) 
        //       Alternately, make a jpeg writer and png writer, as these are 
        //       mostly what we get from jai! 
        if (format.equalsIgnoreCase("image/jpeg")) {
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            param.setCompressionQuality(0.9f); // DJB: only do this for jpegs - png freaks when you do this!
 
            meta = writer.getDefaultStreamMetadata(param);
 
            //           WritableRaster raster = image.getRaster(); 
            //           WritableRaster newRaster = raster.createWritableChild(0, 0, image.getWidth(), image.getHeight(), 0, 0, new int[] {0, 1, 2}); 
            //             create a ColorModel that represents the one of the ARGB except the alpha channel: 
            //            DirectColorModel cm = (DirectColorModel)image.getColorModel(); 
            //           DirectColorModel newCM = new DirectColorModel(cm.getPixelSize(), cm.getRedMask(), cm.getGreenMask(), cm.getBlueMask()); 
            //             now create the new buffer that is used ot write the image: 
            // BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null); 
            BufferedImage curImage = new BufferedImage(image.getWidth(), image.getHeight(),
                    BufferedImage.TYPE_3BYTE_BGR);
            Graphics2D g = (Graphics2D) curImage.createGraphics();

6
CodeRank
This code example shows how to use the following methods:setCompressionMode, setCompressionQuality
See Code Examples for Java 8 ImageWriteParam Methods: