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);
}
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);
}
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);
}
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!");
}
}
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!");
}
}
Aggregations