Hi, i found on a forum a method to read an image's pixel at a given position but they use the "throws IOException" and all this mess, I have no idea what it is... I have been trying the following code but It tells me nullPointException when it's created and it shows me the line with : "int clr = image.getRGB(i, j);"
I tried to put the "reader();" method in the act() method but it tells me: "unreported exception java.io.IOException; must be caught or declared to be thrown"
Could you help me please?
import greenfoot.*;
import java.awt.Color;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
public class Rift1 extends Rift
{
Color[][] pixels = new Color[140][50];
final GreenfootImage baseImage = getImage();
GreenfootImage rift = new GreenfootImage(140, 50);
File file = new File("Rift.png");
BufferedImage image;
public void reader() throws IOException
{
image = ImageIO.read(file);
}
public Rift1()
{
}
public void act()
{
if(isPaused() == false)
{
movements();
for(int i = 0; i<140 ; i++)
{
for (int j = 0; j<50; j++)
{
pixels [i][j] = getWorld().getColorAt(this.getX()-70+i, this.getY()-25+j);
}
}
for(int i = 0; i<140 ; i++)
{
for (int j = 0; j<50; j++)
{
int clr = image.getRGB(i, j);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
Color color = new Color(red, green, blue);
if(color == Color.BLACK)
{
rift.setColorAt(i, j, pixels[i][j]);
}
setImage(rift);
}
}
}
}
public void movements()
{
if(this.getX()>70)
{
move(-1);
}
}
}

