List of usage examples for org.apache.commons.imaging Imaging writeImage
public static void writeImage(final BufferedImage src, final OutputStream os, final ImageFormat format, Map<String, Object> params) throws ImageWriteException, IOException
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. ja va 2 s. 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:org.apache.commons.imaging.examples.SampleUsage.java
@SuppressWarnings("unused") public SampleUsage() { try {//from www . j a va 2s . co m // <b>Code won't work unless these variables are properly // initialized. // Imaging works equally well with File, byte array or InputStream // inputs.</b> final BufferedImage someImage = null; final byte someBytes[] = null; final File someFile = null; final InputStream someInputStream = null; final OutputStream someOutputStream = null; // <b>The Imaging class provides a simple interface to the library. // </b> // <b>how to read an image: </b> final byte imageBytes[] = someBytes; final BufferedImage image_1 = Imaging.getBufferedImage(imageBytes); // <b>methods of Imaging usually accept files, byte arrays, or // inputstreams as arguments. </b> final BufferedImage image_2 = Imaging.getBufferedImage(imageBytes); final File file = someFile; final BufferedImage image_3 = Imaging.getBufferedImage(file); final InputStream is = someInputStream; final BufferedImage image_4 = Imaging.getBufferedImage(is); // <b>Write an image. </b> final BufferedImage image = someImage; final File dst = someFile; final ImageFormat format = ImageFormats.PNG; final Map<String, Object> optionalParams = new HashMap<>(); Imaging.writeImage(image, dst, format, optionalParams); final OutputStream os = someOutputStream; Imaging.writeImage(image, os, format, optionalParams); // <b>get the image's embedded ICC Profile, if it has one. </b> final byte iccProfileBytes[] = Imaging.getICCProfileBytes(imageBytes); final ICC_Profile iccProfile = Imaging.getICCProfile(imageBytes); // <b>get the image's width and height. </b> final Dimension d = Imaging.getImageSize(imageBytes); // <b>get all of the image's info (ie. bits per pixel, size, // transparency, etc.) </b> final ImageInfo imageInfo = Imaging.getImageInfo(imageBytes); if (imageInfo.getColorType() == ImageInfo.ColorType.GRAYSCALE) { System.out.println("Grayscale image."); } if (imageInfo.getHeight() > 1000) { System.out.println("Large image."); } // <b>try to guess the image's format. </b> final ImageFormat imageFormat = Imaging.guessFormat(imageBytes); imageFormat.equals(ImageFormats.PNG); // <b>get all metadata stored in EXIF format (ie. from JPEG or // TIFF). </b> final ImageMetadata metadata = Imaging.getMetadata(imageBytes); // <b>print a dump of information about an image to stdout. </b> Imaging.dumpImageFile(imageBytes); // <b>get a summary of format errors. </b> final FormatCompliance formatCompliance = Imaging.getFormatCompliance(imageBytes); } catch (final Exception e) { } }
From source file:org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriter.java
@Override public void write(IIOMetadata iioMetadata, IIOImage iioImage, ImageWriteParam param) throws IOException { if (ios == null) { throw new IllegalArgumentException(Messages.getString("imageio.7F")); }// www . java 2 s. c o m RenderedImage img = null; if (!iioImage.hasRaster()) { img = iioImage.getRenderedImage(); if (img instanceof BufferedImage) { sourceRaster = ((BufferedImage) img).getRaster(); } else { sourceRaster = img.getData(); } } else { sourceRaster = iioImage.getRaster(); } Map params = new HashMap(); try { Imaging.writeImage((BufferedImage) img, wrapOutput(ios), //(OutputStream)ios, ImageFormats.JPEG, params); } catch (ImageWriteException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.apache.harmony.x.imageio.plugins.png.PNGImageWriter.java
@Override public void write(IIOMetadata streamMetadata, IIOImage iioimage, ImageWriteParam param) throws IOException { if (output == null) { throw new IllegalStateException(Messages.getString("imageio.81")); }// ww w . j ava2 s. c o m if (iioimage == null) { throw new IllegalArgumentException(Messages.getString("imageio.82")); } if (iioimage.hasRaster() && !canWriteRasters()) { throw new UnsupportedOperationException(Messages.getString("imageio.83")); } // ImageOutputStreamImpl RenderedImage image = iioimage.getRenderedImage(); try { Map params = new HashMap(); Imaging.writeImage((BufferedImage) image, wrapOutput(getOutput()), ImageFormats.PNG, params); } catch (ImageWriteException e) { e.printStackTrace(); } }
From source file:org.github.jipsg.sanselan.BaseSanselanTest.java
@Override public void writeBufferedImage(final BufferedImage bufferedImage, final String formatName, final File file) throws Exception { final ImageFormat format = getImageFormat(formatName); final Map<String, Object> params = new HashMap<String, Object>(); Imaging.writeImage(bufferedImage, file, format, params); }
From source file:org.imaging.CommonsImagingVariousExamples.java
public CommonsImagingVariousExamples() { try {/*from w w w .ja va2 s.c om*/ // <b>Code won't work unless these variables are properly // initialized. // Imaging works equally well with File, byte array or InputStream // inputs.</b> final BufferedImage someImage = null; final byte someBytes[] = null; final File someFile = null; final InputStream someInputStream = null; final OutputStream someOutputStream = null; // <b>The Imaging class provides a simple interface to the library. // </b> // <b>how to read an image: </b> final byte imageBytes[] = someBytes; final BufferedImage image_1 = Imaging.getBufferedImage(imageBytes); // <b>methods of Imaging usually accept files, byte arrays, or // inputstreams as arguments. </b> final BufferedImage image_2 = Imaging.getBufferedImage(imageBytes); final File file = someFile; final BufferedImage image_3 = Imaging.getBufferedImage(file); final InputStream is = someInputStream; final BufferedImage image_4 = Imaging.getBufferedImage(is); // <b>Write an image. </b> final BufferedImage image = someImage; final File dst = someFile; final ImageFormat format = ImageFormats.PNG; final Map<String, Object> optionalParams = new HashMap<String, Object>(); Imaging.writeImage(image, dst, format, optionalParams); final OutputStream os = someOutputStream; Imaging.writeImage(image, os, format, optionalParams); // <b>get the image's embedded ICC Profile, if it has one. </b> final byte iccProfileBytes[] = Imaging.getICCProfileBytes(imageBytes); final ICC_Profile iccProfile = Imaging.getICCProfile(imageBytes); // <b>get the image's width and height. </b> final Dimension d = Imaging.getImageSize(imageBytes); // <b>get all of the image's info (ie. bits per pixel, size, // transparency, etc.) </b> final ImageInfo imageInfo = Imaging.getImageInfo(imageBytes); if (imageInfo.getColorType() == ImageInfo.ColorType.GRAYSCALE) { System.out.println("Grayscale image."); } if (imageInfo.getHeight() > 1000) { System.out.println("Large image."); } // <b>try to guess the image's format. </b> final ImageFormat imageFormat = Imaging.guessFormat(imageBytes); imageFormat.equals(ImageFormats.PNG); // <b>get all metadata stored in EXIF format (ie. from JPEG or // TIFF). </b> final ImageMetadata metadata = Imaging.getMetadata(imageBytes); // <b>print a dump of information about an image to stdout. </b> Imaging.dumpImageFile(imageBytes); // <b>get a summary of format errors. </b> final FormatCompliance formatCompliance = Imaging.getFormatCompliance(imageBytes); } catch (final Exception e) { e.printStackTrace(); } }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void writePng(BufferedImage img, File file) throws IOException { if (img == null) { return;/*from w ww .j a v a2 s . c o m*/ } final ImageFormat format = ImageFormats.PNG; try { Imaging.writeImage(img, file, format, null); } catch (ImageWriteException ex) { throw new IOException(ex); } }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void writeBmp(BufferedImage img, File file) throws IOException { if (img == null) { return;/* w ww. j a v a2 s. co m*/ } final ImageFormat format = ImageFormats.BMP; try { Imaging.writeImage(img, file, format, null); } catch (ImageWriteException ex) { throw new IOException(ex); } }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void writePcx(BufferedImage img, File file) throws IOException { if (img == null) { return;//w ww . j ava 2s .co m } final ImageFormat format = ImageFormats.PCX; try { Imaging.writeImage(img, file, format, null); } catch (ImageWriteException ex) { throw new IOException(ex); } }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void writeGif(BufferedImage img, File file) throws IOException { if (img == null) { return;/* w w w . java2 s . c om*/ } final ImageFormat format = ImageFormats.GIF; try { Imaging.writeImage(img, file, format, null); } catch (ImageWriteException ex) { throw new IOException(ex); } }