android - java.lang.IllegalArgumentException: x must be < bitmap.width() -


i'm working on comparing similar images using pixels rbg values in android. i'm following crash @ "pixel_1_final" variable. e; last pixels of image. how last pixel of image.how resolve issue.

01-29 16:23:58.796: e/androidruntime(6211): fatal exception: main 01-29 16:23:58.796: e/androidruntime(6211): process: com.remo.imagecomparation, pid: 6211 01-29 16:23:58.796: e/androidruntime(6211): java.lang.illegalargumentexception: x must < bitmap.width() 01-29 16:23:58.796: e/androidruntime(6211):     @ android.graphics.bitmap.checkpixelaccess(bitmap.java:1387) 01-29 16:23:58.796: e/androidruntime(6211):     @ android.graphics.bitmap.getpixel(bitmap.java:1339) 01-29 16:23:58.796: e/androidruntime(6211):     @ com.remo.imagecomparation.mainactivity$3.onclick(mainactivity.java:109) 01-29 16:23:58.796: e/androidruntime(6211):     @ android.view.view.performclick(view.java:4761) 01-29 16:23:58.796: e/androidruntime(6211):     @ android.view.view$performclick.run(view.java:19767) 01-29 16:23:58.796: e/androidruntime(6211):     @ android.os.handler.handlecallback(handler.java:739) 01-29 16:23:58.796: e/androidruntime(6211):     @ android.os.handler.dispatchmessage(handler.java:95) 01-29 16:23:58.796: e/androidruntime(6211):     @ android.os.looper.loop(looper.java:135) 01-29 16:23:58.796: e/androidruntime(6211):     @ android.app.activitythread.main(activitythread.java:5312) 01-29 16:23:58.796: e/androidruntime(6211):     @ java.lang.reflect.method.invoke(native method) 01-29 16:23:58.796: e/androidruntime(6211):     @ java.lang.reflect.method.invoke(method.java:372) 01-29 16:23:58.796: e/androidruntime(6211):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901) 01-29 16:23:58.796: e/androidruntime(6211):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:696) 

code

 identical_images = (button)findviewbyid(r.id.identical_image);         identical_images.setonclicklistener(new onclicklistener()          {              @override             public void onclick(view arg0)              { //              log.e("compare pixels-------", "-------width------- :"+bmpimg1.getwidth()); //              log.e("compare pixels-------", "-------heigth------- :"+bmpimg1.getheight());                  image_1_params.setmiddlewidth((int)((bmpimg1.getwidth())/ 2));                 image_1_params.setmiddle_width_low((int)(image_1_params.getmiddlewidth() / 2));                 image_1_params.setmiddle_width_high(image_1_params.getmiddlewidth() + image_1_params.middle_width_low);                 image_1_params.setfinalwidth(bmpimg1.getwidth());  //              log.e("compare pixels-------width points", "["+initialwidth+","+middle_width_low+","+middlewidth+","+middle_width_high+","+finalwidth+"]");                  image_1_params.setmiddleheight((int)((bmpimg1.getheight())/ 2));                 image_1_params.setmiddle_height_low((int)(image_1_params.getmiddleheight()/2));                 image_1_params.setmiddle_height_high(image_1_params.getmiddleheight() + image_1_params.getmiddle_height_low());                 image_1_params.setfinalheight(bmpimg1.getheight());  //              log.e("compare pixels-------height points", "["+initialheight+","+middle_height_low+","+middleheight+","+middle_height_high+","+finalheight+"]");  //              log.e("compare pixels-------", "-------final width------- :"+bmpimg1.getpixel(bmpimg1.getwidth(),bmpimg1.getheight()));                  int pixel_1_00 = bmpimg1.getpixel(image_1_params.initialwidth, image_1_params.initialheight); //              globalvarsandfunctions.rbg(pixel_1_00);                  int pixel_1_middle_low = bmpimg1.getpixel(image_1_params.getmiddle_width_low(), image_1_params.getmiddle_height_low()); //              globalvarsandfunctions.rbg(pixel_1_middle_low);                  int pixel_1_middle = bmpimg1.getpixel(image_1_params.getmiddlewidth(), image_1_params.getmiddleheight()); //              globalvarsandfunctions.rbg(pixel_1_middle);                  int pixel_1_middle_high = bmpimg1.getpixel(image_1_params.getmiddle_width_high(), image_1_params.getmiddle_height_high()); //              globalvarsandfunctions.rbg(pixel_1_middle_high);                  int pixel_1_final = bmpimg1.getpixel(image_1_params.getfinalwidth(), image_1_params.getfinalheight());           }); 

i'm not sure libraries you're using, after searching getfinalwidth(). case need append -1 finalwidth().

alternatively, getwidth() not equal getfinalwidth() in of online libraries, try following.

int imagewidth = math.min(image_1_params.getwidth(), image_1_params.getfinalwidth()); int imageheight = math.min(image_1_params.getheight(), image_1_params.getfinalheight()); int pixel_1_final = bmpimg1.getpixel(imagewidth, imageheight); 

Comments