use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class EncodeSubImageTest method write.
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();
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class WriteProgressive method main.
public static void main(String[] args) throws IOException {
Iterator witer = ImageIO.getImageWritersByFormatName("png");
ImageWriter w = (ImageWriter) witer.next();
File f = File.createTempFile("WriteProgressive", ".png");
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
w.setOutput(ios);
BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = bi.createGraphics();
Random r = new Random(10);
for (int i = 0; i < 10000; i++) {
Color c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
g.setColor(c);
g.fillRect(r.nextInt(100), r.nextInt(100), 1, 1);
}
IIOImage iioimage = new IIOImage(bi, null, null);
ImageWriteParam param = w.getDefaultWriteParam();
param.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);
try {
w.write(null, iioimage, param);
} catch (NullPointerException npe) {
throw new RuntimeException("Got NPE during write!");
}
ios.close();
BufferedImage bi2 = ImageIO.read(f);
f.delete();
ImageCompare.compare(bi, bi2);
}
use of javax.imageio.ImageWriteParam in project Lucee by lucee.
the class Image method getImageWriteParam.
private static ImageWriteParam getImageWriteParam(BufferedImage im, ImageWriter writer, float quality, String srcFormat, String trgFormat) {
ImageWriteParam iwp;
if ("jpg".equalsIgnoreCase(srcFormat)) {
ColorModel cm = im.getColorModel();
if (cm.hasAlpha())
im = jpgImage(im);
JPEGImageWriteParam jiwp = new JPEGImageWriteParam(Locale.getDefault());
jiwp.setOptimizeHuffmanTables(true);
iwp = jiwp;
} else
iwp = writer.getDefaultWriteParam();
setCompressionModeEL(iwp, ImageWriteParam.MODE_EXPLICIT);
setCompressionQualityEL(iwp, quality);
return iwp;
}
use of javax.imageio.ImageWriteParam in project litiengine by gurkenlabs.
the class ImageSerializer method saveImage.
public static void saveImage(final String fileName, final BufferedImage image, ImageFormat imageFormat) {
try {
final File file = new File(fileName);
final String extension = FileUtilities.getExtension(fileName);
Iterator<ImageWriter> iter = null;
if (canWriteFormat(extension)) {
iter = ImageIO.getImageWritersByFormatName(extension);
} else {
iter = ImageIO.getImageWritersByFormatName(imageFormat.toString());
}
final ImageWriter writer = iter.next();
final ImageWriteParam iwp = writer.getDefaultWriteParam();
file.getParentFile().mkdirs();
try (final FileImageOutputStream output = new FileImageOutputStream(file.getAbsoluteFile())) {
writer.setOutput(output);
final IIOImage outimage = new IIOImage(image, null, null);
writer.write(null, outimage, iwp);
writer.dispose();
}
} catch (final IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
use of javax.imageio.ImageWriteParam in project sldeditor by robward-scisys.
the class LegendManager method saveGridImage.
/**
* Save image.
*
* @param image the grid image
* @param formatName the format name
* @param destinationFile the output
* @param dpi the dpi
* @return true, if successful
* @throws IOException Signals that an I/O exception has occurred.
*/
private boolean saveGridImage(BufferedImage image, String formatName, File destinationFile, int dpi) throws IOException {
destinationFile.delete();
for (Iterator<ImageWriter> iw = ImageIO.getImageWritersByFormatName(formatName); iw.hasNext(); ) {
ImageWriter writer = iw.next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();
ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
continue;
}
setDPI(metadata, dpi);
final ImageOutputStream stream = ImageIO.createImageOutputStream(destinationFile);
try {
writer.setOutput(stream);
writer.write(metadata, new IIOImage(image, null, metadata), writeParam);
} finally {
stream.close();
}
break;
}
return true;
}
Aggregations