Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.
public Image  images[] = new Image[20];

    for(i=0; i<10; i++){
images[i]=new Image(getClass().getResource("/images/"+i+".jpg"));
        }

I am trying to add images to array but it gives the error Cannot instantiate the type Image j

What can be the reason?

share|improve this question
    
What kind of Image are we talking about? Java's AWT Image? Or do you intend to use Slick's Image perhaps? –  Basaa Sep 23 '13 at 13:46
add comment

1 Answer

Use a BufferedImage and read an image file by ImageIO.read(file). Then you create a raster variable as a picture variable then get pixels from buffered image into that raster or you can directly get the rgb values from buffered image.

 String name="C:\\JoclLwjgl\\rtest\\bubu.png"
 static BufferedImage bi;
 f=new File(name);

    try {
        bi=ImageIO.read(f);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

 Raster pic=bi.getData(new Rectangle(0,0,bi.getWidth(),bi.getHeight()));

 or

 int zz=bi.getRGB(j, i); 
 (float)(zz>>16)&0xff) is "red" component as "float"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.