Call System photo
Intent I = new intent (mediastore. action_image_capture );
File myimagedir = new file (temp_take_photo_file_path );
// Create an image storage directory
If (! Myimagedir. exists ())
{
Mylog. D (this, "create the path:" + temp_take_photo_file_path );
Myimagedir. mkdirs ();
}
// Name by Time
Imagfile = file. createtempfile ("" + system. currenttimemillis (), ". jpg", myimagedir );
Tmpuri = URI. fromfile (imagfile );
I. putextra (mediastore. extra_output, tmpuri );
Startactivityforresult (I, take_photo_request_code );
Select an image from the image library
Intent innerintent = new intent (intent. action_get_content); // "android. Intent. Action. get_content"
Innerintent. settype ("image/*"); // view type
// Stringimage_unspecified = "image/*"; the detailed types are in COM. Google. Android. mms. contenttype.
Intent wrapperintent = intent. createchooser (innerintent, null );
Act. startactivityforresult (wrapperintent, select_photo_request_code );
Receive and call the system cropping Tool
@ Override
Protected void onactivityresult (INT requestcode, int resultcode,
Intent intent ){
If (requestcode = mediahelper. take_photo_request_code | requestcode = mediahelper. select_photo_request_code ){
If (resultcode = result_ OK ){
Uri uri = NULL;
If (requestcode = mediahelper. select_photo_request_code ){
Uri = intent. getdata ();
} Else if (requestcode = mediahelper. take_photo_request_code ){
Uri = mediahelper. tmpuri;
}
If (Uri! = NULL ){
Final intent intent1 = new intent ("com. Android. Camera. Action. Crop ");
Intent1.setdataandtype (Uri, "image /*");
Intent1.putextra ("crop", "true ");
Intent1.putextra ("aspectx", 1 );
Intent1.putextra ("aspecty", 1 );
Intent1.putextra ("outputx", 132 );
Intent1.putextra ("outputy", 132 );
Intent1.putextra ("Return-Data", true );
Startactivityforresult (intent1, mediahelper. cut_photo_request_code );
}
}
Else if (requestcode = mediahelper. cut_photo_request_code ){
If (resultcode = result_ OK & intent! = NULL ){
Bm = intent. getparcelableextra ("data ");
}
}
}
When cropping an image, some images cannot be cropped according to a specified proportion. After checking the source code, you can see that the system's cropping image performs face recognition on the image by default, when a face is identified, it will be processed according to aspectx and aspecty as 1. If you want to set the custom cropping ratio, you need to set nofacedetection to true.
That is, iintent. putextra ("nofacedetection", true); cancels the face recognition function.