use of javax.imageio.stream.MemoryCacheImageInputStream in project openj9 by eclipse.
the class GZipFileManager method getStream.
@Override
public ImageInputStream getStream() throws IOException {
FileInputStream fis = new FileInputStream(managedFile);
GZIPInputStream gis = new GZIPInputStream(fis);
return new MemoryCacheImageInputStream(gis);
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project limelight by slagyr.
the class ImagePanel method setData.
public void setData(byte[] bytes) throws Exception {
ImageInputStream imageInput = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes));
setImage(ImageIO.read(imageInput));
filename = "[DATA]";
markAsNeedingLayout();
getParent().markAsNeedingLayout();
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project zm-mailbox by Zimbra.
the class NativeFormatter method getResizedImageData.
/**
* If the image stored in the {@code MimePart} exceeds the given width,
* shrinks the image and returns the shrunk data. If the
* image width is smaller than {@code maxWidth} or resizing is not supported,
* returns {@code null}.
*/
public static byte[] getResizedImageData(InputStream in, String contentType, String fileName, Integer maxWidth, Integer maxHeight) throws IOException {
ImageReader reader = null;
ImageWriter writer = null;
if (maxWidth == null)
maxWidth = LC.max_image_size_to_resize.intValue();
if (maxHeight == null)
maxHeight = LC.max_image_size_to_resize.intValue();
try {
// Get ImageReader for stream content.
reader = ImageUtil.getImageReader(contentType, fileName);
if (reader == null) {
log.debug("No ImageReader available.");
return null;
}
// Read message content.
reader.setInput(new MemoryCacheImageInputStream(in));
BufferedImage img = reader.read(0);
int width = img.getWidth(), height = img.getHeight();
if (width <= maxWidth && height <= maxHeight) {
log.debug("Image %dx%d is less than max %dx%d. Not resizing.", width, height, maxWidth, maxHeight);
return RETURN_CODE_NO_RESIZE.getBytes();
}
// Resize.
writer = ImageIO.getImageWriter(reader);
if (writer == null) {
log.debug("No ImageWriter available.");
return null;
}
double ratio = Math.min((double) maxWidth / width, (double) maxHeight / height);
width *= ratio;
height *= ratio;
BufferedImage small = ImageUtil.resize(img, width, height);
ByteArrayOutputStream out = new ByteArrayOutputStream();
writer.setOutput(new MemoryCacheImageOutputStream(out));
writer.write(small);
return out.toByteArray();
} finally {
ByteUtil.closeStream(in);
if (reader != null) {
reader.dispose();
}
if (writer != null) {
writer.dispose();
}
}
}
Aggregations