List of usage examples for org.apache.commons.imaging ImagingConstants PARAM_KEY_COMPRESSION
String PARAM_KEY_COMPRESSION
To view the source code for org.apache.commons.imaging ImagingConstants PARAM_KEY_COMPRESSION.
Click Source Link
From source file:editeurpanovisu.ReadWriteImage.java
public static void writeTiff(Image imgImage, String strNomFich, boolean bSharpen, float sharpenLevel) throws ImageReadException, IOException { File file = new File(strNomFich); BufferedImage imageRGBSharpen = null; BufferedImage imageRGB = SwingFXUtils.fromFXImage(imgImage, null); Graphics2D graphics = imageRGB.createGraphics(); graphics.drawImage(imageRGB, 0, 0, null); if (bSharpen) { imageRGBSharpen = new BufferedImage(imageRGB.getWidth(), imageRGB.getHeight(), BufferedImage.TYPE_INT_RGB); Kernel kernel = new Kernel(3, 3, sharpenMatrix); ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); cop.filter(imageRGB, imageRGBSharpen); }//from w w w . j a v a 2s. c o m final ImageFormat format = ImageFormats.TIFF; final Map<String, Object> params = new HashMap<>(); params.put(ImagingConstants.PARAM_KEY_COMPRESSION, new Integer(TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED)); if (bSharpen) { try { Imaging.writeImage(imageRGBSharpen, file, format, params); } catch (ImageWriteException ex) { Logger.getLogger(ReadWriteImage.class.getName()).log(Level.SEVERE, null, ex); } } else { try { Imaging.writeImage(imageRGB, file, format, params); } catch (ImageWriteException ex) { Logger.getLogger(ReadWriteImage.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.java
private byte[] processImage(byte[] imageBytes, List<Rectangle> areasToBeCleaned) { if (areasToBeCleaned.isEmpty()) { return imageBytes; }/* ww w . ja va 2 s .c om*/ try { BufferedImage image = Imaging.getBufferedImage(imageBytes); ImageInfo imageInfo = Imaging.getImageInfo(imageBytes); cleanImage(image, areasToBeCleaned); // Apache can only read JPEG, so we should use awt for writing in this format if (imageInfo.getFormat() == ImageFormats.JPEG) { return getJPGBytes(image); } else { Map<String, Object> params = new HashMap<String, Object>(); if (imageInfo.getFormat() == ImageFormats.TIFF) { params.put(ImagingConstants.PARAM_KEY_COMPRESSION, TiffConstants.TIFF_COMPRESSION_LZW); } return Imaging.writeImageToBytes(image, imageInfo.getFormat(), params); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.commons.imaging.examples.ImageWriteExample.java
public static byte[] imageWriteExample(final File file) throws ImageReadException, ImageWriteException, IOException { // read image final BufferedImage image = Imaging.getBufferedImage(file); final ImageFormat format = ImageFormats.TIFF; final Map<String, Object> params = new HashMap<>(); // set optional parameters if you like params.put(ImagingConstants.PARAM_KEY_COMPRESSION, Integer.valueOf(TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED)); final byte[] bytes = Imaging.writeImageToBytes(image, format, params); return bytes; }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void writeTiff(BufferedImage img, int compression, File file) throws IOException { if (img == null) { return;//from w ww .j a v a 2 s. c o m } final ImageFormat format = ImageFormats.TIFF; final Map<String, Object> params = new HashMap<String, Object>(); switch (compression) { case TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED: case TiffConstants.TIFF_COMPRESSION_CCITT_1D: case TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3: case TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_4: case TiffConstants.TIFF_COMPRESSION_LZW: case TiffConstants.TIFF_COMPRESSION_PACKBITS: //case TiffConstants.TIFF_COMPRESSION_JPEG: break; default: compression = TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED; } ; params.put(ImagingConstants.PARAM_KEY_COMPRESSION, new Integer(compression)); try { Imaging.writeImage(img, file, format, params); } catch (ImageWriteException ex) { throw new IOException(ex); } }