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;
}
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();
}
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");
}
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
}
}
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;
}
}
Aggregations