Call the camera to take a photo to get a picture

Source: Internet
Author: User

In order to get a clear image here, the returned data is not applicable, because this is the thumbnail image. The practice here is to specify where to save the picture before calling the camera, and then get the picture from the file by invoking the result function and the specified picture store path.

To start the camera's code:

1Intent =NewIntent (mediastore.action_image_capture);2File File =NewFile (environment.getexternalstoragedirectory ()3+ "/tempimage.jpg");4ImagePath =File.getabsolutepath ();5Uri Outuri = uri.fromfile (file);//gets the URI of the file6Intent.putextra (Mediastore.extra_output, Outuri);//Specify image storage location7Startactivityforresult (Intent, 2);

To call the camera, you need to add the appropriate permissions, as well as read and write access to the file:

1 <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>2 < Uses-permission android:name= "Android.permission.READ_EXTERNAL_STORAGE"/>3 <uses-permission Android:name= "Android.permission.CAMERA"/>

The image is then read from the file and displayed through the Onactivityresult function:

1 New ImageView (this); 2 // The Imgepath here is the file that you just set up to save the image 3 image.setimagebitmap (Bitmapfactory.decodefile (ImagePath));

Call the camera to take a photo to get a picture

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.