imageio

How to read pixel color in a java BufferedImage with transparency

Hi, I am reading pixel color in a BufferedImage as follows: ..... InputStream is = new BufferedInputStream(conn.getInputStream()); BufferedImage image = ImageIO.read(is); int color = image.getGRB(x, y); int red = (colour & 0x00ff0000) >> 16; int green = (colour & 0x0000ff00) >> 8; int blue = colour & 0x000000ff; Now this works f...

Problem converting PNG to JPG using Java (ImageIO.write())

I am using ImageIO.write() to convert PNG files to JPG. For some reason, my result image has a pink layer over it. I have searched far and wide for a solution but haven't found any. The code works for all other types of images except PNG. ...

PNG to JPG Java ImageIO problem

I have tried both lines of code below to no avail. The code works fine with jpg, or gif but turns the image pink if a png. ImageIO.write(input, "jpg", profileFile); RenderedOp op = JAI.create("filestore", input, pFileName, "jpeg"); Anyone else run into this problem? I haven't been able to find a solution. ...

Is there an easy way to reduce the number of colors in an IndexedColorModel?

I have a large 8-bit PNG image. I am using Java to slice the image into smaller 32x32 images. I use Java's ImageIO to load the PNG into a BufferedImage and then call it's getSubimage(x, y, 32, 32). I then use ImageIO to write each tile out as a PNG. The problem is that the resulting image has the same IndexColorModel as the original ...

Does ImageIO read imply anti-aliased scaling?

I've replaced the Java internal ImageFetcher with an own implementation using ImageIO. Some image renderers of our software, which use these images, now draw anti-aliased scaled images instead of non anti-aliased. The only change is the source of the image, which are now BufferedImages instead of Toolkit-Images. The question now is, whe...

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. ...

Java casting problem

Here is the simplified version of the problem: SomeClass c = (SomeClass) obj.getSomeClassParent() not always but it happens sometimes to trigger exception org.somepackage.SomeClass can't be cast to org.somepackage.SomeClass How is this possible ? I suppose it has something to do with the fact that JAI imageio is native lib,...

Java ImageIO: Can I convert a PNG-24 file to PNG-8?

The scenario is this: Users of the webapp can customize the website by choosing their own logo image, background colors and background images. Problem is that IE6 does not support transparent PNG. I've tried several client-side solutions, but all fall short on one aspect or the other (most don't support the css property background-repea...

jpegs are corrupted when resampled with java imageIO

The JPEG Images that ImageIO generated view correctly on windows file explorer, as well as safari webbrowser, but in FireFox, the resampled images are clipped. How do I use ImageIO without corrupting the resamples? The code should resize image keeping aspect ratio, as well as do jpeg compression, the convert it to a byte [] array, whic...

Java ImageIO: How can I read a BufferedImage from file, so that it uses DataBufferFloat?

Hello, everyone! I need to read a BufferedImage from file, which doesn't use DataBufferInt (as normally), but DataBufferFloat. Please note: I don't just need some standalone DataBufferFloat, but really a BufferedImage with underlying DataBufferFloat. The API around these things is very complex, I just can't find how to do this. Pleas...

Looking for a faster alternative to ImageIO.

I'm attempting to encode a large quantity of BufferedImages to JPEG using the ImageWriter class in javax.imageio. Unfortunately, the encoding operation is quite slow (about 80 to 250 ms per image, not including writing to disk.) This encoding stage ends up being the slowest part of my app, so I'm hoping to optimize it. Does anyone know ...

Problem reading JPEG image using ImageIO.read(File file)

Hi, 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 is that this file seems to include a thumbnail - is that known to cause problems wit...

Java/ImageIO Validate format before reading the entire file ?

I'm developing a Web application that will let users upload images. My concern is the file´s size, specially if they are invalid formats. I'm wondering if there´s a way in java (or a third party library) to check the allowed files formats (jpg, gif and png) before reading the entire file. ...

Java/Groovy File IO Replacing an Image File with it's own Contents - Why Does This Work?

I have some JPG files that need to be replaced at runtime with a JFIF standardized version of themselves (we are using a vendor that gives us JPG that do not have proper headers so they don't work in certain applications)... I am able to create a new file from the existing image, then get a buffered image from that file and write the con...

Manipulating PNGs in Java

Is there an easy way to manipulate PNGs in Java? I know I can read into a BufferedImage and write that back out, but I need to add clear pixels around the edge of an image. Is there an easy way to do this? ...

Imageiio can't create imageinput stream

When using imageio.imageio.read iget a can't create ImageInputStream. I have a catch exception around it so the program survives but i was wondering if theres a way to put an if statement round it that checks to see if it falied and then attempt to read it again if it did. basically asking if there is a test for exceptions? ...

Java: Detecting image format, resize (scale) and save as JPEG

This is the code I have, it actually works, not perfectly but it does, the problem is that the resized thumbnails are not pasting on the white Drawn rectangle, breaking the images aspect ratio, here is the code, could someone suggest me a fix for it, please? Thank you import java.awt.Color; import java.awt.Graphics2D; import java.awt.I...

Java 1.5.0_16 corrupted colours when saving jpg image

Hi, i have a loaded image from disk (stored as a BufferedImage), which i display correctly on a JPanel but when i try to re-save this image using the command below, the image is saved in a reddish hue. ImageIO.write(image, "jpg", fileName); Note! image is a BufferedImage and fileName is a File object pointing to the filename that will...

Error message for failed new ImageIcon(url)

I try to load an image with: ImageIcon imageIcon = new ImageIcon(url); if I query the load status: imageIcon.getImageLoadStatus(); it returns MediaTracker.ERRORED Is there a way to get an error message saying what the problem was? ...

Memory Size Allocation on GPU - opengl texture loading question

I'm loading pixels from an image which is 32 w by 32 height. The format I'm loading them in is ARGB via java. When I bind this to the video card, I can expect that the video card might use somewhere around 32*32*4 bytes, or 4K. Similarly, 1024 w, 1024 h would be 1024*1024*4 = 4MB. Is my understanding correct? Now I understand wh...