
Originally Posted by
r2j7
Which emulator this is about?
I am using the DefaultColorPhone of WTK 2.5.2 for CDLC

Originally Posted by
r2j7
Could you please elaborate more on this code? You mentioned on fetching pics (based on the logs this would be the case, however more info is required for analysis.)
r2j7
gpsCom check in which botanical division of Cypurs the user is located in. I am using a map which is separated into 8 divisions, each with a different color
Code:
public void gpsCom(){
Runtime.getRuntime().freeMemory();
int division = divisionFinder.getDivision();
if (division == -1) {
Alert gps = new Alert("GPS Command", "The botanical division you are located in has not yet been identified.", null, AlertType.INFO);
gps.setTimeout(2000);
display.setCurrent(gps, mainList);
}
else if (division == -2) {
Alert gps = new Alert("GPS Command", "You are not located in any botanical division of Cyprus.", null, AlertType.INFO);
gps.setTimeout(2000);
display.setCurrent(gps, mainList);
}
else{
divisionSelected = division;
GPSLocationForm gpsLocationForm = new GPSLocationForm (this, divisionSelected);
display.setCurrent(gpsLocationForm);
}
}
The value of the corresponding pixel of the map is checked to define which division the user is located in.
Inise divisionFinder Class:
Code:
public int getDivision () {
int division = -1;
if (latitude_N == 0 && longitude_E == 0)
return -1;
if (latitude_N < minLatitude || latitude_N > maxLatitude ||
longitude_E < minLongitude || longitude_E > maxLongitude){
return -2;
}
else {
int[] p = readImagePixel();
if (p[1] > 110 && p[1]<130)
p[1] = 123;
if (p[0] == 0 && p[1] == 123 && p[2] == 255)
division = 1;
else if (p[0] == 255 && p[1] == 123 && p[2] == 0)
division = 2;
else if (p[0] == 0 && p[1] == 123 && p[2] == 0)
division = 3;
else if (p[0] == 255 && p[1] == 123 && p[2] == 255)
division = 4;
else if (p[0] == 255 && p[1] == 255 && p[2] == 0)
division = 5;
else if (p[0] == 255 && p[1] == 0 && p[2] == 0)
division = 6;
else if (p[0] == 0 && p[1] == 255 && p[2] == 0)
division = 7;
else if (p[0] == 0 && p[1] == 0 && p[2] == 255)
division = 8;
else if (p[0] == 255 && p[1] == 255 && p[2] == 255)
division = -2;
}
return division;
}
public int[] readImagePixel () {
Image map = null;
try {
map = Image.createImage("/PlantIdentification/map.png");
} catch (IOException ex) {
ex.printStackTrace();
}
int pixel_x = (int)(((longitude_E - minLongitude) / difLongitude) * (double)map.getWidth());
int pixel_y = (int)((double)map.getHeight() - ((latitude_N - minLatitude) / difLatitude) * (double)map.getHeight());
int[] colorTable = new int[1];
try {
map.getRGB(colorTable, 0, map.getWidth(), pixel_x, pixel_y, 1, 1);
} catch (Exception ex) {
ex.printStackTrace();
}
int[] pixel = new int[3];
pixel[0] = (int)((colorTable[0]&0x00FF0000)>>>16); //Red
pixel[1] = (int)((colorTable[0]&0x0000FF00)>>>8); //Green
pixel[2] = (int)(colorTable[0]&0x000000FF); //Blue
return pixel;
}
The problem occurs when i execute this code starting from gpsCom().