I just want to know some idea on how to scan every pixel from an image file and put it into an array.
Printable View
I just want to know some idea on how to scan every pixel from an image file and put it into an array.
BufferedImage (Java 2 Platform SE 5.0)
look for getRGB
import java.awt.image.*;
import java.awt.*;
import java.applet.*;
public class Sprite {
private String name;
public int[] b;
public int w;
public int h;
public Sprite(Applet a, String filename, int width, int height) {
try {
name=filename.substring(0, filename.indexOf('.'));
w=width;
h=height;
Image img=a.getImage(a.getDocumentBase(), filename);
b=new int[h*w];
PixelGrabber pg= new PixelGrabber(img, 0, 0, w, h, b, 0, w);
pg.grabPixels();
if (pg.status()==192) {
throw new RuntimeException("error loading "+filename +" sprite");
}
//now b[0] is the leftest pixel of the top
// b[w-1] is the rightest pixel of the top
} catch(Exception e) {
e.printStackTrace();
}
}
}
depends upon the format of the image
bitmap stores 3 variables for each pixel
and there must be some api for doing image processing
google for that
i executed but Exception in thred "main" java .lang .No such method error
Please don't resurrect old threads.
Start your own and reference this one if you think it's relevant.
I'm locking this.