Search in sources :

Example 41 with ImageInputStream

use of javax.imageio.stream.ImageInputStream in project d54 by mitrisdev.

the class GNU30Plugin method loadGifObject.

public ArrayList<BufferedImage> loadGifObject(InputStream is) throws IOException {
    ImageInputStream image = ImageIO.createImageInputStream(is);
    ImageReader ir = (ImageReader) ImageIO.getImageReadersBySuffix("gif").next();
    ir.setInput(image, false);
    int frames = ir.getNumImages(true);
    ArrayList<BufferedImage> br = new ArrayList<BufferedImage>();
    for (int i = 0; i < frames; ++i) {
        BufferedImage frame = ir.read(i);
        br.add(frame);
    }
    return br;
}
Also used : ImageInputStream(javax.imageio.stream.ImageInputStream) ArrayList(java.util.ArrayList) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage)

Example 42 with ImageInputStream

use of javax.imageio.stream.ImageInputStream 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 43 with ImageInputStream

use of javax.imageio.stream.ImageInputStream in project intellij-community by JetBrains.

the class ImagePreviewComponent method readImageFromBytes.

@NotNull
public static BufferedImage readImageFromBytes(@NotNull byte[] content) throws IOException {
    InputStream inputStream = new ByteArrayInputStream(content, 0, content.length);
    ImageInputStream imageInputStream = ImageIO.createImageInputStream(inputStream);
    try {
        Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(imageInputStream);
        if (imageReaders.hasNext()) {
            ImageReader imageReader = imageReaders.next();
            try {
                ImageReadParam param = imageReader.getDefaultReadParam();
                imageReader.setInput(imageInputStream, true, true);
                int minIndex = imageReader.getMinIndex();
                return imageReader.read(minIndex, param);
            } finally {
                imageReader.dispose();
            }
        }
    } finally {
        imageInputStream.close();
    }
    throw new IOException("Can't read image from given content");
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) InputStream(java.io.InputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with ImageInputStream

use of javax.imageio.stream.ImageInputStream in project kotlin by JetBrains.

the class IconDetector method checkExtension.

private static void checkExtension(Context context, File file) {
    try {
        ImageInputStream input = ImageIO.createImageInputStream(file);
        if (input != null) {
            try {
                Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
                while (readers.hasNext()) {
                    ImageReader reader = readers.next();
                    try {
                        reader.setInput(input);
                        // Check file extension
                        String formatName = reader.getFormatName();
                        if (formatName != null && !formatName.isEmpty()) {
                            String path = file.getPath();
                            int index = path.lastIndexOf('.');
                            String extension = path.substring(index + 1).toLowerCase(Locale.US);
                            if (!formatName.equalsIgnoreCase(extension)) {
                                if (endsWith(path, DOT_JPG) && formatName.equals("JPEG")) {
                                    //$NON-NLS-1$
                                    return;
                                }
                                String message = String.format("Misleading file extension; named `.%1$s` but the " + "file format is `%2$s`", extension, formatName);
                                Location location = Location.create(file);
                                context.report(ICON_EXTENSION, location, message);
                            }
                            break;
                        }
                    } finally {
                        reader.dispose();
                    }
                }
            } finally {
                input.close();
            }
        }
    } catch (IOException e) {
    // Pass -- we can't handle all image types, warn about those we can
    }
}
Also used : ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader)

Example 45 with ImageInputStream

use of javax.imageio.stream.ImageInputStream in project kotlin by JetBrains.

the class IconDetector method getSize.

private static Dimension getSize(File file) {
    try {
        ImageInputStream input = ImageIO.createImageInputStream(file);
        if (input != null) {
            try {
                Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
                if (readers.hasNext()) {
                    ImageReader reader = readers.next();
                    try {
                        reader.setInput(input);
                        return new Dimension(reader.getWidth(0), reader.getHeight(0));
                    } finally {
                        reader.dispose();
                    }
                }
            } finally {
                input.close();
            }
        }
        // Fallback: read the image using the normal means
        BufferedImage image = ImageIO.read(file);
        if (image != null) {
            return new Dimension(image.getWidth(), image.getHeight());
        } else {
            return null;
        }
    } catch (IOException e) {
        // Pass -- we can't handle all image types, warn about those we can
        return null;
    }
}
Also used : ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ImageInputStream (javax.imageio.stream.ImageInputStream)60 ImageReader (javax.imageio.ImageReader)32 BufferedImage (java.awt.image.BufferedImage)23 IOException (java.io.IOException)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ImageOutputStream (javax.imageio.stream.ImageOutputStream)9 File (java.io.File)8 InputStream (java.io.InputStream)7 IIOImage (javax.imageio.IIOImage)7 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)7 ImageReadParam (javax.imageio.ImageReadParam)6 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)6 ImageWriter (javax.imageio.ImageWriter)6 ImageWriteParam (javax.imageio.ImageWriteParam)5 IIOMetadata (javax.imageio.metadata.IIOMetadata)5 Iterator (java.util.Iterator)4 IIOException (javax.imageio.IIOException)4 Dimension (java.awt.Dimension)2 Graphics (java.awt.Graphics)2