• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

PixelCompare using getRGB()

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where exactly is the problem .. are u getting an error ?

Could you please be a bit more precise.
 
Mohksin Rashid
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh..sorry abt that..ermm..the error came out as this :-

c:\WTK104\apps\PixelCompare\src\PixelCompare.java:78: 'class' or 'interface' expected

public void keyPressed(int keyCode) {
 
reply
    Bookmark Topic Watch Topic
  • New Topic