Method:
Private voidCutphoto (Uri uri) {Intent Intent=NewIntent ("Com.android.camera.action.CROP"); Intent.setdataandtype (URI,"Image/*"); Intent.putextra ("Crop",true); //the scale of the cropping box, 1:1Intent.putextra ("Aspectx", 1); Intent.putextra ("Aspecty", 1); //Size of output picture after croppingIntent.putextra ("Outputx", 250); Intent.putextra ("Outputy", 250); Intent.putextra ("OutputFormat", "JPEG");//Picture FormatIntent.putextra ("Nofacedetection",true);//Remove Face recognitionIntent.putextra ("Return-data",true); Startactivityforresult (Intent, Request_cut_photo); }
Receive method:
@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { Super. Onactivityresult (Requestcode, ResultCode, data); if(ResultCode = =RESULT_OK)Switch(requestcode) { CaseRequest_cut_photo:if(NULL!=data) {Bitmap Bitmap= Data.getparcelableextra ("Data"); Upload (bitmap); } Break; } }
Large Black Edge problem:
Intent Intent =NewIntent (Intent.action_get_content,NULL). SetType ("Image/*"). PutExtra ("Crop", "true"). PutExtra ("Aspectx", width). PutExtra ("Aspecty", height). PutExtra ("Outputx", width). PutExtra ("Outputy", height). PutExtra ("Scale",true)//Black Edge. PutExtra ("scaleupifneeded",true)//Black Edge. PutExtra (Mediastore.extra_output, Uri.fromfile (f)). PutExtra ("OutputFormat", Bitmap.CompressFormat.JPEG.toString ());
Android comes with picture clipping