Search in sources :

Example 1 with ImageReadParam

use of javax.imageio.ImageReadParam in project spring-security-oauth by spring-projects.

the class SparklrController method photo.

@RequestMapping("/sparklr/photos/{id}")
public ResponseEntity<BufferedImage> photo(@PathVariable String id, HttpServletRequest request) throws Exception {
    InputStream photo = sparklrService.loadSparklrPhoto(id);
    if (photo == null) {
        throw new UnavailableException("The requested photo does not exist");
    }
    BufferedImage body;
    MediaType contentType = MediaType.IMAGE_JPEG;
    Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
    if (imageReaders.hasNext()) {
        ImageReader imageReader = imageReaders.next();
        ImageReadParam irp = imageReader.getDefaultReadParam();
        imageReader.setInput(new MemoryCacheImageInputStream(photo), true);
        body = imageReader.read(0, irp);
    } else {
        throw new HttpMessageNotReadableException("Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    request.setAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(MediaType.IMAGE_JPEG));
    return new ResponseEntity<BufferedImage>(body, headers, HttpStatus.OK);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) InputStream(java.io.InputStream) UnavailableException(javax.servlet.UnavailableException) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) MediaType(org.springframework.http.MediaType) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ImageReadParam

use of javax.imageio.ImageReadParam in project spring-security-oauth by spring-projects.

the class SparklrRedirectController method photo.

@RequestMapping("/sparklr/redirect/{id}")
public ResponseEntity<BufferedImage> photo(@PathVariable String id) throws Exception {
    InputStream photo = sparklrService.loadSparklrPhoto(id);
    if (photo == null) {
        throw new UnavailableException("The requested photo does not exist");
    }
    BufferedImage body;
    MediaType contentType = MediaType.IMAGE_JPEG;
    Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
    if (imageReaders.hasNext()) {
        ImageReader imageReader = imageReaders.next();
        ImageReadParam irp = imageReader.getDefaultReadParam();
        imageReader.setInput(new MemoryCacheImageInputStream(photo), true);
        body = imageReader.read(0, irp);
    } else {
        throw new HttpMessageNotReadableException("Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    return new ResponseEntity<BufferedImage>(body, headers, HttpStatus.OK);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) InputStream(java.io.InputStream) UnavailableException(javax.servlet.UnavailableException) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) MediaType(org.springframework.http.MediaType) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ImageReadParam

use of javax.imageio.ImageReadParam in project spring-security-oauth by spring-projects.

the class SparklrController method photo.

@RequestMapping("/sparklr/photos/{id}")
public ResponseEntity<BufferedImage> photo(@PathVariable String id) throws Exception {
    InputStream photo = sparklrService.loadSparklrPhoto(id);
    if (photo == null) {
        throw new UnavailableException("The requested photo does not exist");
    }
    BufferedImage body;
    MediaType contentType = MediaType.IMAGE_JPEG;
    Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
    if (imageReaders.hasNext()) {
        ImageReader imageReader = imageReaders.next();
        ImageReadParam irp = imageReader.getDefaultReadParam();
        imageReader.setInput(new MemoryCacheImageInputStream(photo), true);
        body = imageReader.read(0, irp);
    } else {
        throw new HttpMessageNotReadableException("Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    return new ResponseEntity<BufferedImage>(body, headers, HttpStatus.OK);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) InputStream(java.io.InputStream) UnavailableException(javax.servlet.UnavailableException) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) MediaType(org.springframework.http.MediaType) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ImageReadParam

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

the class ImageReaderReadAll method main.

public static void main(String[] argv) {
    ImageReader ireader;
    ImageReadParam irp;
    IIOImage image;
    BufferedImage bi;
    BufferedImage bi_1;
    BufferedImage bi_2;
    ireader = new DummyImageReaderImpl(null);
    MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream(new ByteArrayInputStream(ba));
    ireader.setInput(mciis);
    irp = new ImageReadParam();
    irp.setDestination(new BufferedImage(10, 10, BufferedImage.TYPE_3BYTE_BGR));
    try {
        image = ireader.readAll(0, irp);
        bi_1 = ireader.read(0, irp);
        bi_2 = ireader.read(0);
    } catch (java.io.IOException ee) {
        throw new RuntimeException("Unexpected exception: " + ee);
    }
    bi = (BufferedImage) image.getRenderedImage();
    if (bi.getType() != bi_1.getType()) {
        throw new RuntimeException("Images have different type!");
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage) IIOImage(javax.imageio.IIOImage)

Example 5 with ImageReadParam

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

the class ImageReadParamPasses method checkForIAE.

private static void checkForIAE(int minPass, int numPasses) {
    ImageReadParam param = new ImageReadParam();
    boolean gotIAE = false;
    try {
        param.setSourceProgressivePasses(minPass, numPasses);
    } catch (IllegalArgumentException iae) {
        gotIAE = true;
    }
    if (!gotIAE) {
        throw new RuntimeException("Failed to get IAE for wraparound!");
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam)

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