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
8
votes
3 answers

Why does loading this jpg using JavaIO give CMMException?

ImageIO.read(imagePath) with this file gives a CMMException, why cant Java cope with this seemingly valid file http://www.jthink.net/jaikoz/scratch/front.jpg java.awt.color.CMMException: Invalid image format at…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
8
votes
1 answer

Image changes color when saved with java

When I save this image: with this method: private final static Path ROOT_PATH = Paths.getPath("C:/images"); private static void saveImageFromWebSimple(final String url) { URL u = null; try { u = new URL(url); } catch…
Franz Ebner
  • 4,951
  • 3
  • 39
  • 57
8
votes
4 answers

How to create image in Java

say in my program, i have this paint() method. my wish is to create an image of the rectangles that are drawn (with the for loop). I tried the method below and it did give me those rectangles (blue color), but the background is all black. When I run…
dorothy
  • 1,213
  • 5
  • 20
  • 35
8
votes
1 answer

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

I want to save canvas object as image, and for this I want use ImageIO class. I'm using Eclipse, but when I try make import of this lib (import javax.imageio.ImageIO;) Eclipse is shows me an error "The import javax.imageio cannot be resolved". Pls.…
Ivan B
  • 394
  • 1
  • 5
  • 18
8
votes
2 answers

Toolkit.getDefaultToolkit().createImage() vs ImageIO.read()

I'm creating a UI using Swing and I want to display an image in a JLabel. The code I use is the following: JLabel label = new JLabel(new ImageIcon(ImageIO.read(new File("img.jpg")))); This works fine if I use png images but when it comes to jpg…
user1612150
7
votes
2 answers

Writing jpg or jpeg image with ImageIO.write does not create image file

I recreated the issue in a minimal form: MAIN: public class ImageIOMain extends Application { @Override public void start(Stage stage) throws Exception{ Scene scene = new Scene(new StackPane(), 800.0, 600.0); …
Ricky
  • 553
  • 6
  • 21
7
votes
2 answers

Why does ImageReader return incorrect BufferedImage?

I'm trying to access a animated GIF image with 21 frames and then read the 12th (cause it starts at 0?) frame. import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import…
Rihards
  • 10,241
  • 14
  • 58
  • 78
7
votes
3 answers

Unable to acquire image through ImageIO.read(url) because of connection timed out

The following code always seems to fail: URL url = new URL("http://userserve-ak.last.fm/serve/126/8636005.jpg"); Image img = ImageIO.read(url); System.out.println(img); I've checked the url, and it is a valid jpg image. The error I get…
Jake Frederix
  • 79
  • 1
  • 1
  • 2
7
votes
2 answers

Tiff compression using Java ImageIO

I am having issues converting a png to tiff. The conversion goes fine, but the image is huge. I think the issue is that I am not doing the compression correctly? Anyone have any suggestions?? Here is the code sample public static void test()…
CFreiner
  • 465
  • 1
  • 5
  • 12
7
votes
2 answers

ImageIO thread-safety

I see in the javax.imageio spec that thread-safety is not a goal, despite I've seen several examples using ImageIO.read() and ImageIO.write() for uploading/sanitizing images in a web environment. So, my question is, despite what the spec says, is…
Alex
  • 327
  • 1
  • 3
  • 12
7
votes
3 answers

Java ImageIO.write return false

I want to save a BufferedImage (named "result"): boolean bres = ImageIO.write(result, ".png", new File(saveP)); But bres is always null. This ImageIO.getWriterFormatNames() returns that: jpg BMP bmp JPG jpeg wbmp png JPEG PNG WBMP GIF gif I…
user3363881
  • 101
  • 1
  • 5
7
votes
3 answers

Byte array to buffered image conversion slow

I have a simple server-side code that receives a byte array representing an image in JPEG format and returns the dimensions of the image. public String processImage(byte[] data) { long startTime = System.currentTimeMillis(); …
baekacaek
  • 1,527
  • 3
  • 22
  • 45
7
votes
7 answers

Eclipse bug : javax.imageio.IIOException: Can't read input file

The following code is running successfully in BlueJ IDE, but not in Eclipse. String path="images/pic1.jpg"; BufferedImage myPicture = null; try { myPicture = ImageIO.read(new File(path)); } catch (IOException e) { // TODO…
paraguma
  • 187
  • 1
  • 1
  • 7
7
votes
1 answer

Java reading image from URL hanging

I'm trying to get an image off the internet from an URL in java. I'm using the following code. URL url = new URL(webAddress); image = ImageIO.read(url); Sometimes it works and sometimes it just hangs indefinitely, depending on what WebAddress is.…
Bergil
  • 85
  • 2
  • 7
6
votes
1 answer

Java BufferedImage saves with unwanted background color

Thanks ahead of time for the help Description: The program draws, displays, and saves an image. It works as following: the object itself extends Frame. In the constructor, the object creates a BufferedImage, and calls a method that draw onto that…
whearyou
  • 358
  • 1
  • 5
  • 18