Search in sources :

Example 1 with FileImageInputStream

use of javax.imageio.stream.FileImageInputStream in project skin-composer by raeleus.

the class Utils method doesImageFitBox.

public static boolean doesImageFitBox(FileHandle fileHandle, float width, float height) {
    boolean result = false;
    String suffix = fileHandle.extension();
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageReader reader = iter.next();
        try {
            ImageInputStream stream = new FileImageInputStream(fileHandle.file());
            reader.setInput(stream);
            int imageWidth = reader.getWidth(reader.getMinIndex());
            int imageHeight = reader.getHeight(reader.getMinIndex());
            result = imageWidth < width && imageHeight < height;
        } catch (IOException e) {
            Gdx.app.error(Utils.class.getName(), "error checking image dimensions", e);
        } finally {
            reader.dispose();
        }
    } else {
        Gdx.app.error(Utils.class.getName(), "No reader available to check image dimensions");
    }
    return result;
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) MathUtils(com.badlogic.gdx.math.MathUtils) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader)

Example 2 with FileImageInputStream

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

the class VMDataFactory method getStructureDataFromFile.

private static ImageInputStream getStructureDataFromFile(String fileName, IProcess addressSpace) throws IOException {
    File blobFile = new File(fileName);
    ImageInputStream iis = new FileImageInputStream(blobFile);
    iis.setByteOrder(addressSpace.getByteOrder());
    return iis;
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) IMemoryImageInputStream(com.ibm.j9ddr.corereaders.memory.IMemoryImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) File(java.io.File)

Example 3 with FileImageInputStream

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

the class FileSniffer method isZipFile.

public static boolean isZipFile(File file) throws IOException {
    FileImageInputStream fis = new FileImageInputStream(file);
    boolean result = isZipFile(fis);
    fis.close();
    return result;
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream)

Example 4 with FileImageInputStream

use of javax.imageio.stream.FileImageInputStream in project OpenOLAT by OpenOLAT.

the class ImageHelperImpl method scaleImage.

/**
 * @param image The image to scale
 * @param imageExt The extension if not given by the image file (optional)
 * @param scaledImaged the new scaled image
 * @param maxWidth the maximum width of the new scaled image
 * @param maxheight the maximum height of the new scaled image
 * @return
 */
@Override
public Size scaleImage(File image, String imageExt, File scaledImage, int maxWidth, int maxHeight, boolean fill) {
    ImageInputStream imageSrc = null;
    try {
        imageSrc = new FileImageInputStream(image);
        SizeAndBufferedImage scaledSize = calcScaledSize(imageSrc, imageExt, maxWidth, maxHeight, fill);
        if (scaledSize == null || scaledSize.image == null) {
            return null;
        }
        if (!scaledSize.getScaledSize().isChanged() && isSameFormat(image, imageExt, scaledImage)) {
            if (FileUtils.copyFileToFile(image, scaledImage, false)) {
                return scaledSize.getSize();
            }
        }
        BufferedImage bufferedImage = scaledSize.image;
        BufferedImage scaledBufferedImage = scaleTo(bufferedImage, scaledSize.getScaledSize());
        if (writeTo(scaledBufferedImage, scaledImage, scaledSize.getScaledSize(), getImageFormat(scaledImage))) {
            return scaledSize.getScaledSize();
        }
        return null;
    } catch (IOException e) {
        return null;
    // fxdiff FXOLAT-109: prevent red screen if the image has wrong EXIF data
    } catch (CMMException e) {
        return null;
    } finally {
        closeQuietly(imageSrc);
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) CMMException(java.awt.color.CMMException) BufferedImage(java.awt.image.BufferedImage)

Example 5 with FileImageInputStream

use of javax.imageio.stream.FileImageInputStream in project OpenOLAT by OpenOLAT.

the class ImageHelperImpl method cropImage.

@Override
public boolean cropImage(File image, File cropedImage, Crop cropSelection) {
    try (ImageInputStream imageSrc = new FileImageInputStream(image)) {
        String extension = FileUtils.getFileSuffix(cropedImage.getName());
        SizeAndBufferedImage img = getImage(imageSrc, extension);
        if (img != null) {
            BufferedImage croppedImg = cropTo(img.getImage(), img.getSize(), cropSelection);
            Size size = new Size(cropSelection.getWidth(), cropSelection.getHeight(), false);
            return writeTo(croppedImg, cropedImage, size, extension);
        }
        return false;
    } catch (IOException e) {
        return false;
    } catch (CMMException e) {
        // if the image has wrong EXIF data
        return false;
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) Size(org.olat.core.commons.services.image.Size) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) CMMException(java.awt.color.CMMException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

FileImageInputStream (javax.imageio.stream.FileImageInputStream)36 File (java.io.File)22 BufferedImage (java.awt.image.BufferedImage)19 IOException (java.io.IOException)16 ImageInputStream (javax.imageio.stream.ImageInputStream)16 ImageReader (javax.imageio.ImageReader)14 Test (org.junit.Test)14 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)10 TIFFImageReaderSpi (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi)9 TIFFImageReader (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader)7 RenderedImage (java.awt.image.RenderedImage)7 ImageReadParam (javax.imageio.ImageReadParam)7 Rectangle (java.awt.Rectangle)6 FileImageOutputStream (javax.imageio.stream.FileImageOutputStream)4 CMMException (java.awt.color.CMMException)3 InputStream (java.io.InputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 IIOImage (javax.imageio.IIOImage)3 ImageOutputStream (javax.imageio.stream.ImageOutputStream)3 JPEGImageReaderSpi (com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi)2