hi all, ive got a problem debugging my code..its not working.. can somebody take a look at it?
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
import java.io.*;
public class PixelCompare extends MIDlet implements CommandListener {
private Command exitCommand;
private Display display;
private SSCanvas screen;
public PixelCompare() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 2);
screen = new SSCanvas();
screen.addCommand(exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
display.setCurrent(screen);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class SSCanvas extends Canvas {
private Image[] slides;
private
String[] captions = {"Superman"};
private int curSlide = 0;
public SSCanvas() {
try {
slides = new Image[2];
slides[0] = Image.createImage("/superman1.png");
}
catch (IOException e) {
System.err.println("Failed Loading images!");
}
}
public void keyPressed(int keyCode) {
int action = getGameAction(keyCode);
switch (action) {
case LEFT:
if (--curSlide < 0)
curSlide = slides.length - 1;
repaint();
break;
}
}
public void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(slides[curSlide], getWidth() / 2, getHeight() / 2,
Graphics.HCENTER | Graphics.VCENTER);
Font f = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
Font.SIZE_LARGE);
g.setFont(f);
g.setColor(0, 0, 255);
g.drawString(captions[curSlide], getWidth() / 2, 0,
Graphics.HCENTER | Graphics.TOP);
}
}
public void keyPressed(int keyCode) {
int action = getGameAction(keyCode);
switch (action) {
case LEFT:
//using this method : public int[] getPixelData(Image capturedImage)
int[] pixData = getPixelData(slides[0]);
System.out.println ("One value of the edge: "+pixData[0]);
repaint();
break;
}
}
public void getRGB(int[] rgbData,
int offset,
int scanlength,
int x,
int y,
int width,
int height) {
rgbData[offset + (a - x) + (b - y) * scanlength] = P(a, b);
public void int[] getPixelData(Image capturedImage)throws Exception{
//Initialise the array to return
int[] pixelData = new int[capturedImage.getHeight() * capturedImage.getWidth()];
int pOffset = 0;
int pScanLength = capturedImage.getWidth();
try{
//Get the RGB array
capturedImage.getRGB(pixelData, pOffset, pScanLength, 0, 0, capturedImage.getWidth(), capturedImage.getHeight());
//pixelData has the ARGB values of the Image
}catch(Exception e){
throw new Exception("Cannot get pixel values from Image.");
}finally{
/*@- Nothing to clean up here@@*/
}
return pixelData;
}
public void int[] getGrayData(int[] imageARGBData)throws Exception{
int[] grayData = new int[imageARGBData.length];
//parse through the input array
int grayValue = 255;
for( int j= (imageARGBData.length -1); j >= 0 ; j--){
//(r + g + b)/3
grayValue = (((imageARGBData[j] >> 16) & 0x00FF) +((imageARGBData[j] >> 8) & 0x0000FF) + (imageARGBData[j] & 0x000000FF));
grayValue = grayValue / 3;
grayData[j] = grayValue ;
}
return grayData;
}