views:

438

answers:

3

I'm trying to load a gif image from a url into a java.util.image.Raster so I can manipulate it. The only method for loading and decompressing an image I could find was Toolkit.getImage, which returns a java.awt.Image. I need to turn that into a Raster so I can work with it. Suggestions?

+1  A: 

Load your Image into a Buffered Image and then get the data from it

BufferedImage img = null;
try {
   img = ImageIO.read(new File ("c:/imageFile.gif"));
} catch(Exception e) {}

Raster R=img.getData();
Rickster
A: 

if you just want to draw on this image, you can get a Graphics2D context, from your BufferedImage.

Graphics2D g=(Graphics2D) image.getGraphics();
//draw over your image
g.drawLine(1,1,100,100);
g.dispose();
//save your image, display it, etc...
Pierre
A: 

Rickster sent me down the right path (thanks!).

import javax.imageio.ImageIO;

public Raster get_image(InputStream inp) {
    return ImageIO.read(inp).getData();
}

public Raster get_image(URL inp) {
    return ImageIO.read(inp).getData();
}
rabidsnail
You should select his answer and set his answer to helpful then.
stevedbrown