Questions tagged [javax.imageio]

The Java Image I/O API (the javax.imageio package) contains the basic classes and interfaces for reading/writing BufferedImages and RenderedImages from/to image files and streams.

The Java Image I/O API (the javax.imageio package) contains the basic classes and interfaces for reading/writing BufferedImages and RenderedImages from/to image files and streams.

Many common image I/O operations may be performed using the static methods of the ImageIO class.

The package contains classes describing the contents of image files, including metadata and thumbnails (IIOImage); for controlling the image reading process (ImageReader, ImageReadParam, and ImageTypeSpecifier) and image writing process (ImageWriter and ImageWriteParam); for performing transcoding between formats (ImageTranscoder), and for reporting errors (IIOException).

All implementations of javax.imageio provide the following standard image format plug-ins: JPEG, PNG, BMP, WBMP and GIF.

The javax.imageio package has been available since Java (J2SE) 1.4.

1092 questions
139
votes
7 answers

Java - get pixel array from image

I'm looking for the fastest way to get pixel data (int the form int[][]) from a BufferedImage. My goal is to be able to address pixel (x, y) from the image using int[x][y]. All the methods I have found do not do this (most of them return int[]s).
ryyst
  • 9,563
  • 18
  • 70
  • 97
130
votes
14 answers

How to get image height and width using java?

Is there any other way besides using ImageIO.read to get image height and width? Because I encounter an issue that locks up the thread. at com.sun.medialib.codec.jpeg.Decoder.njpeg_decode(Native Method) at…
Dick Song
68
votes
4 answers

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

Is there a way to get the dimensions of an image without reading the entire file? URL url=new URL(); BufferedImage img=ImageIO.read(url); System.out.println(img.getWidth()+" "+img.getHeight()); img=null;
Pierre
  • 34,472
  • 31
  • 113
  • 192
62
votes
6 answers

ImageIO not able to write a JPEG file

I have a BufferedImage I'm trying to write to a jpeg file, but my Java program throws an exception. I'm able to successfully save the same buffer to a gif and png. I've tried looking around on Google for solutions, but to no avail. Code: File…
Karan
  • 1,636
  • 4
  • 19
  • 35
61
votes
4 answers

How to return a PNG image from Jersey REST service method to the browser

I have a web server running with Jersey REST resources up and I wonder how to get an image/png reference for the browsers img tag; after submitting a Form or getting an Ajax response. The image processing code for adding graphics is working, just…
gorn
  • 8,097
  • 5
  • 37
  • 44
60
votes
5 answers

Setting jpg compression level with ImageIO in Java

I'm using javax.imageio.ImageIO to save a BufferedImage as a jpeg file. In particular, I created the following Java function: public static void getScreenShot(BufferedImage capture, Path folder, String filename) { try { …
mat_boy
  • 12,998
  • 22
  • 72
  • 116
57
votes
9 answers

Problem setting exif data for an image

I'm using the new ImageIO framework in iOS 4.1. I successfully retrieve the exif metadata using the following: CFDictionaryRef metadataDict = CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary , NULL); Reading it out, it appears valid.…
akaru
  • 6,299
  • 9
  • 63
  • 102
51
votes
3 answers

How to get an InputStream from a BufferedImage?

How can I get an InputStream from a BufferedImage object? I tried this but ImageIO.createImageInputStream() always returns NULL BufferedImage bigImage = GraphicsUtilities.createThumbnail(ImageIO.read(file), 300); ImageInputStream bigInputStream =…
lbrandao
  • 4,144
  • 4
  • 35
  • 43
50
votes
6 answers

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

I'm having problems reading this one JPEG file using ImageIO.read(File file) - it throws an exception with the message "Unsupported Image Type". I have tried other JPEG images, and they seem to work fine. The only differance I've been able to spot…
Malakim
  • 1,333
  • 2
  • 18
  • 34
35
votes
5 answers

Java ImageIO IIOException: Unsupported image type?

Working with images in Java for the first time and am getting some bizarro exceptions that aren't documented very well. Here's the line of code that is failing: BufferedImage imgSelected = ImageIO.read(new File("/abs/url/to/file/image.jpg")); This…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
32
votes
4 answers

ImageIO reading slightly different RGB values than other methods

I've found that I'm getting different RGB when using Java (& actually paint.NET) than I am using ImageMagick, Gimp, Python, and Octave. The last 4 all agreeing with eachother and so I'm assuming to be correct. For these examples, I'm using this test…
matt burns
  • 24,742
  • 13
  • 105
  • 107
32
votes
3 answers

ImageIO - get image type and exif data

Given some source file (or more generic - input stream), I need to find out is it an image if it is an image, then retrieve its type (png/jpeg/gif/etc) retrieve exif data, if available I looked at the API, but it is not clear how to get the type…
jdevelop
  • 12,176
  • 10
  • 56
  • 112
28
votes
2 answers

ArrayIndexOutOfBoundsException: 4096 while reading gif file

I am able to read png file. But getting ArrayIndexOutOfBoundsException: 4096 while reading gif file. byte[] fileData = imageFile.getFileData(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileData); RenderedImage image =…
Venkat Janyavula
  • 615
  • 2
  • 7
  • 10
28
votes
6 answers

Turn an array of pixels into an Image object with Java's ImageIO?

I'm currently turning an array of pixel values (originally created with a java.awt.image.PixelGrabber object) into an Image object using the following code: public Image getImageFromArray(int[] pixels, int width, int height) { MemoryImageSource…
Chris Carruthers
  • 3,945
  • 6
  • 31
  • 31
27
votes
5 answers

Can't read and write a TIFF image file using Java ImageIO standard library

I don't know what to do with TIFF images, but I can't read or write any of them using straight Java standard ImageIO library. Any thoughts? Thanks.
Gle
  • 281
  • 1
  • 3
  • 4
1
2 3
72 73