Android Call System camera feature

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.