java - Using getPixel and setPixel to convert image into grayscale -


i new programming , need know how use getpixels convert image have grayscale.pls me: ( need image gallery, convert bitmap , start doing image processing. have 2 days left submission. need using getpixels.

public class selectimageactivity extends activity implements onclicklistener {      // image loading result pass startactivityforresult method.     private static int load_image_results = 1;      // gui components     private button button;  // button     private imageview image;// imageview      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_select_image);          // find references gui objects         button = (button)findviewbyid(r.id.button);         image = (imageview)findviewbyid(r.id.image);          // set button's onclick listener object.         button.setonclicklistener(this);      }      @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);          // here need check if activity triggers image gallery.         // if requestcode match load_image_results value.         // if resultcode result_ok , there data know image picked.         if (requestcode == load_image_results && resultcode == result_ok && data != null) {             // let's read picked image data - uri             uri pickedimage = data.getdata();             // let's read picked image path using content resolver             string[] filepath = { mediastore.images.media.data };             cursor cursor = getcontentresolver().query(pickedimage, filepath, null, null, null);             cursor.movetofirst();             string imagepath = cursor.getstring(cursor.getcolumnindex(filepath[0]));              bitmap bitmap1=bitmapfactory.decodefile(imagepath);             int threshold=50;             int result[];              (int x=0; x<bitmap1.getwidth();x++)             {                 (int y=0; y<bitmap1.getheight();y++)                 {                      if (bitmap1.getpixel(x, y)>threshold)                          result[x,y]=255; () //((i have error here saying "the primitive type int of x not have field y"))                     else                          result[x,y]=0;                     }                     } 

i think reason error the primitive type int of x not have field y result array initialization. should wrote :

int[][] result = new int[bitmap1.getwidth()][bitmap1.getheight()]; 

instead of int result[]; , access element using result[x][y].


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -