android - How to crop an image and set to imageVeiw -


im trying crop image taken camera , store imageview - m not sure how target cropped image, seems stored in gallery im not bothered if or not.

problem: crop method works puts original image in imageview.

how can assign cropped image imageview?

   private static final int pick_image = 0;     private static final int pick_image_from_gallery = 1;     private static final int crop_image = 2;     private uri uri; 

. . .

     btnphotocamera.setonclicklistener(new view.onclicklistener() {              public void onclick(view v) {                  intent camera=new intent();                 camera.setaction(mediastore.action_image_capture);                 //camera.putextra("crop", "true");                  file f=environment.getexternalstoragepublicdirectory(environment.directory_pictures);                  uri = uri.fromfile(new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures),"myfile.jpg"));                 camera.putextra(mediastore.extra_output, uri);                 startactivityforresult(camera, pick_image);             }         }); 

then crop method

 private void performcrop(uri picuri)             {                 //nexus 5 os 5 example of branch                 // take care of exceptions                 try {                     // call standard crop action intent (the user device may not                     // support it)                      intent cropintent = new intent("com.android.camera.action.crop");                     // indicate image type , uri                     cropintent.setdataandtype(uri, "image/*");                     // set crop properties                     cropintent.putextra("crop", "true");                     // // indicate aspect of desired crop                     cropintent.putextra("aspectx", 1);                     cropintent.putextra("aspecty", 1);                     // // // indicate output x , y                      // retrieve data on return                     cropintent.putextra("return-data", true);                     // start activity - handle returning in onactivityresult                     startactivityforresult(cropintent, crop_image);                 }                 // respond users devices not support crop action                 catch (activitynotfoundexception anfe)                 {//not tested hw not go here                     toast toast = toast.maketext(this,"this device doesn't support crop action! exception: " + anfe.tostring(),toast.length_short);                     toast.show();                 }             } 

then method catch fired intents (other apps) , results.

      protected void onactivityresult(int requestcode, int resultcode, intent data)         {             // todo auto-generated method stub             if (resultcode==result_ok )             {                 if(requestcode == pick_image) //reply camera                 {                     performcrop(uri); //crop picture                 }                  if(requestcode == crop_image) //reply crop                 {                     bitmap bmp = getbitmap(uri);                     imgview.setimagebitmap(bmp);                 }          }     } 

and method converts uri bitmap - im going wrong, why uri not cropped? how can overwrite uri witht cropped one?

    private bitmap getbitmap(uri bitmap_uri) {         inputstream is=null;         try         {             = this.getcontentresolver().openinputstream(bitmap_uri);         }         catch (filenotfoundexception e)         {             e.printstacktrace();         }         return bitmapfactory.decodestream(is);     } } 

fetch image intent received, not own (old) uri:

//reply crop if(requestcode == crop_image) {     bundle extras = data.getextras();     if (extras != null) {         bitmap bmp = extras.getparcelable("data");         imgview.setimagebitmap(bmp);     } } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -