Search in sources :

Example 46 with MemoryCacheImageInputStream

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);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) FileInputStream(java.io.FileInputStream)

Example 47 with MemoryCacheImageInputStream

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream)

Example 48 with MemoryCacheImageInputStream

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();
        }
    }
}
Also used : MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) ImageWriter(javax.imageio.ImageWriter) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage)

Aggregations

MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)48 ImageInputStream (javax.imageio.stream.ImageInputStream)28 ByteArrayInputStream (java.io.ByteArrayInputStream)22 ImageReader (javax.imageio.ImageReader)21 InputStream (java.io.InputStream)18 BufferedImage (java.awt.image.BufferedImage)16 IOException (java.io.IOException)16 FileInputStream (java.io.FileInputStream)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 EOFException (java.io.EOFException)5 ImageReadParam (javax.imageio.ImageReadParam)5 MemoryCacheImageOutputStream (javax.imageio.stream.MemoryCacheImageOutputStream)5 Point (java.awt.Point)4 Size (org.olat.core.commons.services.image.Size)4 Point2D (java.awt.geom.Point2D)3 ArrayList (java.util.ArrayList)3 IIOImage (javax.imageio.IIOImage)3 ImageWriter (javax.imageio.ImageWriter)3 FileImageInputStream (javax.imageio.stream.FileImageInputStream)3 UnavailableException (javax.servlet.UnavailableException)3