use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class UshortGrayTest method main.
public static void main(String[] args) {
Iterator iter;
BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_USHORT_GRAY);
// Part 1: ensure that JPEGImageWriter throws an exception if it
// encounters an image with 16-bit samples
ImageWriter writer = null;
iter = ImageIO.getImageWritersByFormatName("jpeg");
if (iter.hasNext()) {
writer = (ImageWriter) iter.next();
} else {
throw new RuntimeException("No JPEG reader found");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = null;
boolean exceptionThrown = false;
try {
ios = ImageIO.createImageOutputStream(baos);
} catch (IOException ioe) {
throw new RuntimeException("Could not create ImageOutputStream");
}
try {
writer.setOutput(ios);
writer.write(bi);
} catch (IOException ioe) {
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("JPEG writer should not be able to " + "write USHORT_GRAY images");
}
// Part 2: ensure that JPEGImageWriterSpi.canEncodeImage() returns
// false for images with 16-bit samples
ImageTypeSpecifier its = ImageTypeSpecifier.createFromRenderedImage(bi);
iter = ImageIO.getImageWriters(its, "jpeg");
if (iter.hasNext()) {
throw new RuntimeException("JPEG writer should not be available" + " for USHORT_GRAY images");
}
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class MergeStdCommentTest method main.
public static void main(String[] args) throws Exception {
String format = "javax_imageio_1.0";
BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
DOMImplementationRegistry registry;
registry = DOMImplementationRegistry.newInstance();
DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
Document doc = impl.createDocument(null, format, null);
Element root, text, entry;
root = doc.getDocumentElement();
root.appendChild(text = doc.createElement("Text"));
text.appendChild(entry = doc.createElement("TextEntry"));
// keyword isn't #REQUIRED by the standard metadata format.
// However, it is required by the PNG format, so we include it here.
entry.setAttribute("keyword", "Comment");
entry.setAttribute("value", "Some demo comment");
meta.mergeTree(format, root);
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class DestTypeTest method getWriteParam.
public ImageWriteParam getWriteParam() {
ImageWriteParam p = w.getDefaultWriteParam();
p.setSourceBands(new int[] { 0, 1, 2 });
ImageTypeSpecifier type = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
p.setDestinationType(type);
return p;
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class ImageTypeSpecifierTest method test4429934.
private static void test4429934() {
try {
ImageTypeSpecifier itspecifier = new ImageTypeSpecifier(null, null);
fail("Failed to get IAE!");
} catch (IllegalArgumentException e) {
}
try {
ImageTypeSpecifier itspecifier = new ImageTypeSpecifier(null);
fail("Failed to get IAE!");
} catch (IllegalArgumentException e) {
}
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class ImageTypeSpecifierTest method test4430993.
private static void test4430993() {
ImageTypeSpecifier itspecifier;
int bits = 32;
int rmask = 0x00ff0000;
int gmask = 0x0000ff00;
int bmask = 0x000000ff;
ColorModel dcm = new java.awt.image.DirectColorModel(bits, rmask, gmask, bmask);
int[] bandOffsets = new int[2];
bandOffsets[1] = 1;
SampleModel sm = new java.awt.image.ComponentSampleModel(DataBuffer.TYPE_SHORT, 1, 1, 2, 2, bandOffsets);
try {
itspecifier = new ImageTypeSpecifier(dcm, sm);
fail("Failed to get IAE!");
} catch (IllegalArgumentException e) {
}
}
Aggregations