Search code examples
javaimageawtraster

How do I get a Raster from an Image in java?


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?


Solution

  • 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();