imageio

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 mis = new MemoryImageSource(width, height, pixels, 0, width); Toolkit tk = Toolkit.ge...

Loading animated gif from JAR file into ImageIcon

I'm trying to create a ImageIcon from a animated gif stored in a jar file. ImageIcon imageIcon = new ImageIcon(ImageIO.read(MyClass.class.getClassLoader().getResourceAsStream("animated.gif"))); The image loads, but only the first frame of the animated gif. The animation does not play. If I load the animated gif from a file on the f...

Write dpi metadata to a jpeg image in Java

I am trying to programatically set the dpi metadata of an jpeg image in Java. The source of the image is a scanner, so I get the horizontal/vertical resolution from TWAIN, along with the image raw data. I'd like to save this info for better print results. Here's the code I have so far. It saves the raw image (byteArray) to a JPEG file, ...

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() throws IOException { // String fileName = "4958813_1"; String fileName = "4848970_1"; St...

Convert PNG to bitonal TIFF

-Edit- FYI.. I am converting b&w documents scanned in as greyscale or color. 1)The first solution worked, it just reversed black & white (black background, white text). It also took nearly 10 minutes. 2)The JAI solution in the 2nd answer didn't work for me. I tried it before posting here. Has anyone worked with other libraries free ...

How to use ImageIO to save multiple BufferedImages to a file

I tried both of the following options: <1> BufferedImage Buffered_Image; MemoryCacheImageOutputStream MemoryCache_OutputStream=new MemoryCacheImageOutputStream(new FileOutputStream("C:/Test.mov",false)); while (notFinished) // Main recording loop. { Buffered_Image=robot.createScreenCapture(); // Capture Screen image. tr...

ImageIO.write not saving out as gif, but works for jpgs and pngs?

I suspect the solution here is probably really simple, but I'm stumped... // Create the buffered image. BufferedImage bufferedImage = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB); ... //fill image data (works fine) ImageIO.write(bufferedImage, "JPG", f1); // works fine ImageIO.write(bufferedImage, "PNG", f2); //works fine Image...

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 = ImageIO.createImageInputStream(bigImage); The image thumbnail is being correctly generate...

How to get image height and width using java?

Is there any other way beside using imageIO.read to get image height and width? Because I encounter some issue that will lockup the thread. at com.sun.medialib.codec.jpeg.Decoder.njpeg_decode(Native Method) at com.sun.medialib.codec.jpeg.Decoder.decode(Decoder.java:87) at com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImage...

How can I save a PNG with a tEXt or iTXt chunk from Java?

I am currently using javax.imageio.ImageIO to write a PNG file. I would like to include a tEXt chunk (and indeed any of the chunks listed here), but can see no means of doing so. By the looks of com.sun.imageio.plugins.png.PNGMetadata it should be possible. I should be most grateful for any clues or answers. M. ...

Is there a good alternative to javax.imageio out there?

I'm looking for a good alternative to the javax.imageio package, that lets me do simple rotating, cutting and scaling operations on images. For example, I would like to do int angle, height, width; image.rotateRight(angle).scale(height, width); in order to obtain an image that is rotated angle degrees to the right and scaled down to h...

Creating animated GIF with ImageIO?

Has anybody managed to convince ImageIO to write an animated GIF, and in particular setting the correct metadata? My first attempt is roughly as follows (where b1 and b2 are BufferedImages): ImageTypeSpecifier spec = new ImageTypeSpecifier(b1); ImageWriter wr = ImageIO.getImageWriters(spec, "GIF").next(); wr.setOutput(ImageIO.createImag...

Access non-public classes in sun.awt package [specifically: FetcherInfo]

Question: I have some performance problem in my app - and the bottleneck is sun.awt.image.ImageFetcher.run, and I canno't get any (more) meaningfull info from profiler. So I figured that it would be nice to look at jobs that ImageFetcher is doing. I couldn't get access to FetcherInfo class, that holds all ImageFetcher jobs. To obtain ...

NullPointerException using ImageIO.read

I'm getting an NPE while trying to read in an image file, and I can't for the life of me figure out why. Here is my line: BufferedImage source = ImageIO.read(new File(imgPath)); imgPath is basically guaranteed to be valid and right before it gets here it copies the file from the server. When it hits that line, I get this stack trace...

Why the jpg file I converted from a gif file isn't crisp and clear ?

I use the following code to convert a gif file to a jpg file, it works but the result jpg file isn't the same quality as the original gif file, why ? Any way to improve the quality ? try { ImageIO.write(ImageIO.read(new File("C:/abc.gif")),"jpg",new File("C:/abc.jpg")); } catch (Exception e) { e.printStackTrace(); } So, to ask this ...

Retrieve an image from the web in java

Hi i am trying to read an image that resides somewhere on the web from my Java program. So far i have successfully loaded an image by using the following code. URL url = new URL("http://www.google.com/images/nav_logo4.png"); Image img = Toolkit.getDefaultToolkit().getImage(url); What i want to know is why this code (which is the first...

Convert Byte Array to image in Java - without knowing the type

Sounds simple right? Use ImageIO.read(new ByteArrayInputStream(bytes)); Here's the wrinkle. For some reason it is detecting a jpeg as a bmp, and that is the first ImageReader returned when I call ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(bytes)); Iterator<ImageReader> readers=ImageIO.getImageRea...

Why Java ImageIO flattens JPEG colors

When I read certain JPG files, colors are flattened. Here is a simple example that reads a jpg and just writes the same image to another file. import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; public class JPegReadTest { public static void main(String[] args) { if (args.length == 2) { ...

Image that doesn't show up in IE or Chrome only

I have a jpeg that shows up properly in FF, but won't appear in IE or Chrome. I tried downloading the image and loading it in IE and Chrome directly without success: both browsers shows a broken icon. So this is not a network issue. This file is a result of an image resize by javax.imageio.ImageIO. I have processed over 1000 images succ...

Java/ImageIO Getting Image Dimension without reading the entire file ?

Hi all, is there a way to get the dimension of an image without reading the entire file ? URL url=new URL(<BIG_IMAGE_URL>); BufferedImage img=ImageIO.read(url); System.out.println(img.getWidth()+" "+img.getHeight()); img=null; Thanks ...