use of javax.imageio.ImageWriter in project jdk8u_jdk by JetBrains.
the class XDataTransferer method getPlatformMappingsForFlavor.
/*
* The XDnD protocol prescribes that the Atoms used as targets for data
* transfer should have string names that represent the corresponding MIME
* types.
* To meet this requirement we return a list of formats that represent
* MIME types to which the data in this flavor can be translated by the Data
* Transfer subsystem.
*/
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
LinkedHashSet<String> natives = new LinkedHashSet<>(1);
if (df == null) {
return natives;
}
String charset = df.getParameter("charset");
String baseType = df.getPrimaryType() + "/" + df.getSubType();
String mimeType = baseType;
if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
mimeType += ";charset=" + charset;
}
// doesn't require translation.
if (df.getRepresentationClass() != null && (df.isRepresentationClassInputStream() || df.isRepresentationClassByteBuffer() || byte[].class.equals(df.getRepresentationClass()))) {
natives.add(mimeType);
}
if (DataFlavor.imageFlavor.equals(df)) {
String[] mimeTypes = ImageIO.getWriterMIMETypes();
if (mimeTypes != null) {
for (int i = 0; i < mimeTypes.length; i++) {
Iterator writers = ImageIO.getImageWritersByMIMEType(mimeTypes[i]);
while (writers.hasNext()) {
ImageWriter imageWriter = (ImageWriter) writers.next();
ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider();
if (writerSpi != null && writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
natives.add(mimeTypes[i]);
break;
}
}
}
}
} else if (DataTransferer.isFlavorCharsetTextType(df)) {
// "text/plain" MIME type.
if (DataFlavor.stringFlavor.equals(df)) {
baseType = "text/plain";
}
for (String encoding : DataTransferer.standardEncodings()) {
if (!encoding.equals(charset)) {
natives.add(baseType + ";charset=" + encoding);
}
}
// Add a MIME format without specified charset.
if (!natives.contains(baseType)) {
natives.add(baseType);
}
}
return natives;
}
use of javax.imageio.ImageWriter in project jdk8u_jdk by JetBrains.
the class LUTCompareTest method createTestImage.
/* Create test image with two frames:
* 1) with {red, red} palette
* 2) with {blue, red } palette
*/
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");
}
use of javax.imageio.ImageWriter in project jdk8u_jdk by JetBrains.
the class BmpBigDestinationTest method main.
public static void main(String[] args) {
try {
BufferedImage src = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
Graphics2D g = src.createGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageWriter iw = (ImageWriter) ImageIO.getImageWritersByFormatName(format).next();
if (iw == null) {
throw new RuntimeException("No writer available. Test failed.");
}
iw.setOutput(ImageIO.createImageOutputStream(baos));
iw.write(src);
byte[] data = baos.toByteArray();
ImageReader ir = (ImageReader) ImageIO.getImageReadersByFormatName(format).next();
ir.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(data)));
Iterator specifiers = ir.getImageTypes(0);
ImageTypeSpecifier typeSpecifier = null;
if (specifiers.hasNext()) {
typeSpecifier = (ImageTypeSpecifier) specifiers.next();
}
ImageReadParam param = new ImageReadParam();
BufferedImage dst = typeSpecifier.createBufferedImage(200, 200);
param.setDestination(dst);
ir.read(0, param);
checkResults(src, dst);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Unexpected exception. Test failed.");
}
}
use of javax.imageio.ImageWriter in project jdk8u_jdk by JetBrains.
the class CompressionModeTest method doTest.
private static void doTest(int mode) {
String fileFormat = "bmp";
try {
ImageWriter iw = (ImageWriter) ImageIO.getImageWritersBySuffix(fileFormat).next();
if (iw == null) {
throw new RuntimeException("No available image writer for " + fileFormat + " Test failed.");
}
File file = new File("image." + fileFormat);
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
iw.setOutput(ios);
BufferedImage bimg = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
Graphics g = bimg.getGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, 100, 100);
ImageWriteParam param = iw.getDefaultWriteParam();
param.setCompressionMode(mode);
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bimg), param);
IIOImage iioImg = new IIOImage(bimg, null, meta);
iw.write(null, iioImg, param);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Test failed.");
}
}
use of javax.imageio.ImageWriter in project jdk8u_jdk by JetBrains.
the class TopDownTest method writeWithCompression.
private static void writeWithCompression(BufferedImage src, String compression) throws IOException {
System.out.println("Compression: " + compression);
ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
if (writer == null) {
throw new RuntimeException("Test failed: no bmp writer available");
}
File fout = File.createTempFile(compression + "_", ".bmp", new File("."));
ImageOutputStream ios = ImageIO.createImageOutputStream(fout);
writer.setOutput(ios);
BMPImageWriteParam param = (BMPImageWriteParam) writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType(compression);
param.setTopDown(true);
writer.write(null, new IIOImage(src, null, null), param);
writer.dispose();
ios.flush();
ios.close();
BufferedImage dst = ImageIO.read(fout);
verify(dst);
}
Aggregations