Search in sources :

Example 16 with MemoryCacheImageInputStream

use of javax.imageio.stream.MemoryCacheImageInputStream in project openolat by klemens.

the class ImageUtils method getImageSize.

public static Size getImageSize(String suffix, InputStream in) {
    Size result = null;
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageReader reader = iter.next();
        try {
            ImageInputStream stream = new MemoryCacheImageInputStream(in);
            reader.setInput(stream);
            int imageIndex = reader.getMinIndex();
            int width = reader.getWidth(imageIndex);
            int height = reader.getHeight(imageIndex);
            result = new Size(width, height, 0, 0, false);
        } catch (IOException e) {
            log.error(e.getMessage());
        } finally {
            IOUtils.closeQuietly(in);
            reader.dispose();
        }
    } else {
        log.error("No reader found for given format: " + suffix);
    }
    return result;
}
Also used : ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader)

Example 17 with MemoryCacheImageInputStream

use of javax.imageio.stream.MemoryCacheImageInputStream in project openolat by klemens.

the class AbstractImageHelper method getImageSize.

private Size getImageSize(VFSLeaf media, String suffix) {
    Size result = null;
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageInputStream stream = null;
        InputStream mediaStream = null;
        ImageReader reader = iter.next();
        try {
            mediaStream = media.getInputStream();
            if (mediaStream != null) {
                stream = new MemoryCacheImageInputStream(mediaStream);
                reader.setInput(stream);
                int readerMinIndex = reader.getMinIndex();
                int width = reader.getWidth(readerMinIndex);
                int height = reader.getHeight(readerMinIndex);
                result = new Size(width, height, 0, 0, false);
            }
        } catch (IOException e) {
            log.error(e.getMessage());
        } finally {
            IOUtils.closeQuietly(stream);
            IOUtils.closeQuietly(mediaStream);
            reader.dispose();
        }
    } else {
        log.error("No reader found for given format: " + suffix);
    }
    return result;
}
Also used : Size(org.olat.core.commons.services.image.Size) FileInputStream(java.io.FileInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) InputStream(java.io.InputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader)

Example 18 with MemoryCacheImageInputStream

use of javax.imageio.stream.MemoryCacheImageInputStream in project openolat by klemens.

the class AbstractImageHelper method getImageSize.

private Size getImageSize(File media, String suffix) {
    Size result = null;
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageReader reader = iter.next();
        try (InputStream mediaStream = new FileInputStream(media);
            ImageInputStream stream = new MemoryCacheImageInputStream(mediaStream)) {
            reader.setInput(stream);
            int readerMinIndex = reader.getMinIndex();
            int width = reader.getWidth(readerMinIndex);
            int height = reader.getHeight(readerMinIndex);
            result = new Size(width, height, 0, 0, false);
        } catch (IOException e) {
            log.error(e.getMessage());
        } finally {
            reader.dispose();
        }
    } else {
        log.error("No reader found for given format: " + suffix);
    }
    return result;
}
Also used : Size(org.olat.core.commons.services.image.Size) FileInputStream(java.io.FileInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) InputStream(java.io.InputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader) FileInputStream(java.io.FileInputStream)

Example 19 with MemoryCacheImageInputStream

use of javax.imageio.stream.MemoryCacheImageInputStream in project wcomponents by BorderTech.

the class ThumbnailUtil method createImageThumbnail.

/**
 * This method will create a JPEG "thumb nail" of an image read from an {@link InputStream}. The maximum Dimension
 * of the returned JPEG Image will be {@link #THUMBNAIL_MAX}.
 *
 * @param is the InputStream representing the image for which the JPEG thumb nail is to be returned.
 * @param scaledSize the size to which the given <em>image</em> is to be scaled.
 * @return a byte[] representing the JPEG thumb nail.
 */
private static byte[] createImageThumbnail(final InputStream is, final Dimension scaledSize) {
    BufferedImage image;
    MemoryCacheImageInputStream mciis;
    try {
        mciis = new MemoryCacheImageInputStream(is);
        image = ImageIO.read(mciis);
    } catch (Exception e) {
        LOG.warn("Unable to read input image", e);
        return null;
    }
    if (image == null) {
        return null;
    }
    try {
        byte[] jpeg = createScaledJPEG(image, scaledSize);
        return jpeg;
    } catch (Exception e) {
        LOG.error("Error creating thumbnail from image", e);
    } finally {
        image.flush();
    }
    return null;
}
Also used : MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException)

Example 20 with MemoryCacheImageInputStream

use of javax.imageio.stream.MemoryCacheImageInputStream in project openj9 by eclipse.

the class UnwindTable method dumpInstructions.

/*
	 * Dump the instructions, basically a copy of processInstruction with just the print
	 * statements left in.
	 * Some instructions create rules, others adjust the address the instructions 
	 * apply to and others save/restore state to a stack.
	 * See: DWARF Debugging Information Format, Version 3 section 6.4.2
	 * (Also extra instructions defined for Exception handling in:
	 * http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html
	 * )
	 */
public static void dumpInstructions(PrintStream out, byte[] instructions, CIE cie) throws IOException {
    try {
        InputStream i = new ByteArrayInputStream(instructions);
        ImageInputStream instructionStream = new MemoryCacheImageInputStream(i);
        instructionStream.setByteOrder(cie.byteOrder);
        while (instructionStream.getStreamPosition() < instructions.length) {
            dumpInstruction(out, instructionStream, cie);
            out.println();
        }
    } catch (Exception e) {
        out.println("Error dumping instructions: " + e);
        e.printStackTrace(out);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) IOException(java.io.IOException)

Aggregations

MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)54 ImageInputStream (javax.imageio.stream.ImageInputStream)33 ByteArrayInputStream (java.io.ByteArrayInputStream)23 ImageReader (javax.imageio.ImageReader)22 IOException (java.io.IOException)19 InputStream (java.io.InputStream)19 BufferedImage (java.awt.image.BufferedImage)17 FileInputStream (java.io.FileInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 COSDictionary (org.apache.pdfbox.cos.COSDictionary)8 EOFException (java.io.EOFException)7 ArrayList (java.util.ArrayList)6 COSStream (org.apache.pdfbox.cos.COSStream)6 PDRange (org.apache.pdfbox.pdmodel.common.PDRange)6 Point (java.awt.Point)5 Point2D (java.awt.geom.Point2D)5 ImageReadParam (javax.imageio.ImageReadParam)5 MemoryCacheImageOutputStream (javax.imageio.stream.MemoryCacheImageOutputStream)5 Paint (java.awt.Paint)4 Size (org.olat.core.commons.services.image.Size)4