Can’t import javax.imageio.ImageIO in Android application

You have tagged your question with Android. javax.imageio.ImageIO is not part of the Android platform, so unfortunately you can’t use it. Instead you need to use what’s available in the Android SDK for reading and storing images. Have a look at the Bitmap and BitmapFactory classes for a starting point. These classes contains the necessary … Read more

Including Images with an executable jar

Files in a Jar are not files in the sense of a file on disk. They are simply a (possibly) compressed stream of bytes. Java makes it easy to extract these “resources” from Jar files through the use of the ClassLoader background = ImageIO.read(getClass().getResource(“/wood.jpeg”)); Should work… This will return a URL which ImageIO can use … Read more

Unable to read JPEG image using ImageIO.read(File file)

Old post, but for future reference: Inspired by this question and links found here, I’ve written a JPEGImageReader plugin for ImageIO that supports CMYK color models (both with original color model, or implicitly converted to RGB on read). The reader also does proper color conversion, using the ICC profile embedded in the JPEG stream, in … Read more

Convert each animated GIF frame to a separate BufferedImage

If you want all the frames to be the same size (for optimized GIFs) try something like this: try { String[] imageatt = new String[]{ “imageLeftPosition”, “imageTopPosition”, “imageWidth”, “imageHeight” }; ImageReader reader = (ImageReader)ImageIO.getImageReadersByFormatName(“gif”).next(); ImageInputStream ciis = ImageIO.createImageInputStream(new File(“house2.gif”)); reader.setInput(ciis, false); int noi = reader.getNumImages(true); BufferedImage master = null; for (int i = 0; i … Read more

Java/ImageIO getting image dimensions without reading the entire file?

try(ImageInputStream in = ImageIO.createImageInputStream(resourceFile)){ final Iterator<ImageReader> readers = ImageIO.getImageReaders(in); if (readers.hasNext()) { ImageReader reader = readers.next(); try { reader.setInput(in); return new Dimension(reader.getWidth(0), reader.getHeight(0)); } finally { reader.dispose(); } } } Thanks to sfussenegger for the suggestion