Search in sources :

Example 11 with ImageReadParam

use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.

the class ReadAsGrayTest method testType.

private static void testType(ImageReader reader, ImageTypeSpecifier t, BufferedImage src) throws IOException {
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);
    verify(src, dst, t);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) BufferedImage(java.awt.image.BufferedImage)

Example 12 with ImageReadParam

use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.

the class ReadingInterruptionTest method doTest.

public void doTest() {
    try {
        reader.addIIOReadProgressListener(this);
        iis = ImageIO.createImageInputStream(file);
        reader.setInput(iis);
        ImageReadParam p = reader.getDefaultReadParam();
        Thread.sleep(70);
        BufferedImage res = reader.read(0, p);
        Thread.sleep(70);
    } catch (Exception e) {
        /*
             * we do expect that concurrent attempt to dispose this
             * instance of image reader will be blocked. So, this image
             * should be read sucessfuly. Otherwise, something went wrong
             * and we need to report test failure.
             */
        throw new RuntimeException("Test FAILED", e);
    } finally {
        /*
             * it would happen that concurrent invocation of dispose() method
             * will be successful. Due to race condition it seems to be possible
             * that dispose operation will be performed after than read() operation
             * leaveled thread lock. In this case all subsequent calls for reader
             * methods should results in IllegalStateException. So, we treat
             * IllegalStateException as success. Everything else means test failure.
             */
        try {
            reader.reset();
        } catch (IllegalStateException e) {
            System.out.println("Expected exception was caught: " + e);
        } catch (Exception e) {
            throw new RuntimeException("Test FAILED.", e);
        }
    }
    System.out.println("Test PASSED.");
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException)

Example 13 with ImageReadParam

use of javax.imageio.ImageReadParam 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;
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageReadParam(javax.imageio.ImageReadParam) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 14 with ImageReadParam

use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.

the class ConcurrentReadingTest method run.

public void run() {
    try {
        ImageInputStream iis = ImageIO.createImageInputStream(file);
        r.setInput(iis);
        ImageReadParam p = r.getDefaultReadParam();
        Thread.sleep(70);
        BufferedImage res = r.read(0, p);
        Thread.sleep(70);
        r.reset();
    } catch (IllegalStateException e) {
        System.out.println(e);
    } catch (IOException e) {
        System.out.println(e);
    } catch (Throwable e) {
        // Unexpected exception. Test failed.
        throw new RuntimeException("Test failed.", e);
    } finally {
        synchronized (lock) {
            completeCount++;
        }
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 15 with ImageReadParam

use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.

the class WbmpBigDestinationTest method main.

public static void main(String[] args) {
    try {
        BufferedImage src = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_BINARY);
        Graphics2D g = src.createGraphics();
        g.setColor(Color.white);
        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.");
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageWriter(javax.imageio.ImageWriter) Iterator(java.util.Iterator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) Graphics2D(java.awt.Graphics2D)

Aggregations

ImageReadParam (javax.imageio.ImageReadParam)20 BufferedImage (java.awt.image.BufferedImage)16 ImageReader (javax.imageio.ImageReader)14 IOException (java.io.IOException)9 ImageInputStream (javax.imageio.stream.ImageInputStream)6 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)5 MediaType (org.springframework.http.MediaType)4 Graphics2D (java.awt.Graphics2D)3 Iterator (java.util.Iterator)3 UnavailableException (javax.servlet.UnavailableException)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Rectangle (java.awt.Rectangle)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ImageWriter (javax.imageio.ImageWriter)2