In the general application development process, we often use the camera function to the phone, by invoking the system camera to quickly and easily help us to achieve the photo function, this article I will lead you to realize how to take photos by invoking the system camera.
First: Call the system camera to take pictures and show us the pictures by returning the photo thumbnails
Open the System camera:
New Intent (mediastore.action_image_capture); Startactivityforresult (Intent, take_picture); // if using Activity.result_ok,onactivityresult () will not be callback
Process Photo return parameters:
protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { if(ResultCode = =RESULT_OK) { //Get system default return picture (thumbnail) if(Requestcode = =take_picture) {Bundle Bundle=Data.getextras (); Bitmap= (BITMAP) bundle.Get("Data"); } //Show PicturesIv.setimagebitmap (bitmap); }}
is not very simple, but one thing is not good, that is the return of the image is a thumbnail, then how to get the high-definition pictures taken?
The second type: Save the photo to the specified file, display the photo by the file path
Private StaticFinalintAdd_image_one =1;//take a photo return valuePrivateString path;//path of picture saving after taking picturesPrivateString FileName;//Save file namePath = environment.getexternalstoragedirectory () +"/ceshi/image/"; File File=NewFile (path);//Create Pathif(!file.exists ()) {File.mkdirs ();} FileName="copyimage.jpg"; File F=NewFile (path+fileName);if(!f.exists ()) {Try{f.createnewfile ();//Create a file}Catch(IOException E1) {e1.printstacktrace (); }}intent Intent=NewIntent (mediastore.action_image_capture); Intent.putextra (Mediastore.extra_output, Uri.fromfile (f)); Startactivityforresult (Intent, add_image_one);
Data processing after the shooting is complete:
protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {Super.onactivityresult (Requestcode, ResultCode, data);if(ResultCode = =ACTIVITY.RESULT_OK) {Switch(requestcode) { CaseAdd_image_one://photo shoot//Toast.maketext (Mcontext, "photo complete", Toast.length_short). Show ();Iv.setimagebitmap (bitmapfactory.decodefile (path +fileName)); Break; default: Break; }}}
OK, about the call system camera to complete the knowledge of the photo shoot, to summarize, I hope to help you. SOURCE Download: http://pan.baidu.com/s/1sjZMUQx
Android Call System camera feature