use of javax.imageio.ImageReader in project jdk8u_jdk by JetBrains.
the class EmptyInputBmpMetadataTest method main.
public static void main(String[] args) {
boolean isPassed = false;
ImageReader ir = (ImageReader) ImageIO.getImageReadersByFormatName(fmt).next();
if (ir == null) {
throw new RuntimeException("No available reader for " + fmt);
}
IIOMetadata meta = null;
try {
meta = ir.getImageMetadata(0);
} catch (IllegalStateException e) {
System.out.println("Correct exception was thrown. Test passed.");
isPassed = true;
} catch (IOException e) {
e.printStackTrace();
}
if (!isPassed) {
throw new RuntimeException("The IllegalStateException was not thrown." + "Test failed.");
}
}
use of javax.imageio.ImageReader in project jdk8u_jdk by JetBrains.
the class ITXtTest method readFrom.
private static ITXtTest readFrom(File f) {
try {
ImageInputStream iis = ImageIO.createImageInputStream(f);
ImageReader r = ImageIO.getImageReaders(iis).next();
r.setInput(iis);
IIOImage dst = r.readAll(0, null);
// look for iTXt node
IIOMetadata m = dst.getMetadata();
Node root = m.getAsTree(m.getNativeMetadataFormatName());
Node n = root.getFirstChild();
while (n != null && !"iTXt".equals(n.getNodeName())) {
n = n.getNextSibling();
}
if (n == null) {
throw new RuntimeException("No iTXt node!");
}
ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode) n);
return t;
} catch (Throwable e) {
throw new RuntimeException("Reading test failed.", e);
}
}
use of javax.imageio.ImageReader in project jdk8u_jdk by JetBrains.
the class ReadAsGrayTest method doTest.
private static void doTest(int type) throws IOException {
BufferedImage src = createTestImage(type);
File f = new File("test.jpg");
if (!ImageIO.write(src, "jpg", f)) {
throw new RuntimeException("Failed to write test image.");
}
ImageInputStream iis = ImageIO.createImageInputStream(f);
ImageReader reader = ImageIO.getImageReaders(iis).next();
reader.setInput(iis);
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
ImageTypeSpecifier srgb = null;
ImageTypeSpecifier gray = null;
// look for gray and srgb types
while ((srgb == null || gray == null) && types.hasNext()) {
ImageTypeSpecifier t = types.next();
if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
gray = t;
}
if (t.getColorModel().getColorSpace() == sRGB) {
srgb = t;
}
}
if (gray == null) {
throw new RuntimeException("No gray type available.");
}
if (srgb == null) {
throw new RuntimeException("No srgb type available.");
}
System.out.println("Read as GRAY...");
testType(reader, gray, src);
System.out.println("Read as sRGB...");
testType(reader, srgb, src);
}
use of javax.imageio.ImageReader in project jdk8u_jdk by JetBrains.
the class JPEGsNotAcceleratedTest method readTestImage.
public static BufferedImage readTestImage(String fileName, BufferedImage dest, Rectangle srcROI) {
BufferedImage bi = null;
try {
FileImageInputStream is = new FileImageInputStream(new File(fileName));
ImageReader reader = (ImageReader) ImageIO.getImageReaders(is).next();
ImageReadParam param = reader.getDefaultReadParam();
if (dest != null) {
param.setDestination(dest);
}
if (srcROI != null) {
param.setSourceRegion(srcROI);
}
reader.setInput(is);
bi = reader.read(0, param);
} catch (IOException e) {
System.err.println("Error " + e + " when reading file: " + fileName);
throw new RuntimeException(e);
}
return bi;
}
use of javax.imageio.ImageReader in project jdk8u_jdk by JetBrains.
the class NullInputOutput method main.
public static void main(String[] args) throws Exception {
IIORegistry registry = IIORegistry.getDefaultInstance();
// test ImageReader.read() for all available ImageReaders
Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class, false);
while (readerspis.hasNext()) {
ImageReaderSpi readerspi = (ImageReaderSpi) readerspis.next();
ImageReader reader = readerspi.createReaderInstance();
try {
reader.read(0);
} catch (IllegalStateException ise) {
// caught exception, everything's okay
}
}
// test ImageWriter.write() for all available ImageWriters
BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
Iterator writerspis = registry.getServiceProviders(ImageWriterSpi.class, false);
while (writerspis.hasNext()) {
ImageWriterSpi writerspi = (ImageWriterSpi) writerspis.next();
ImageWriter writer = writerspi.createWriterInstance();
try {
writer.write(bi);
} catch (IllegalStateException ise) {
// caught exception, everything's okay
}
}
}
Aggregations