Android calls camera to take pictures to get original photos

Source: Internet
Author: User

Android calls the camera to take pictures and get the original photo solution as follows:
Note to have permission to read the file, you need to add the following permissions:
<uses-permission android:name= "Android.permission.CAMERA"/>
button click event:

 Public voidClick (View view) {Intent Intent=NewIntent (mediastore.action_image_capture);//the intention of the camera to capture the pictureIntent.putextra (Mediastore.extra_output, Imagefileuri);//specifies that the system camera is saved in the location indicated by ImagefileuriStartactivityforresult (Intent, capture_pic);//start the system camera and wait to return} @Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {             if(ResultCode = = Result_ok && Requestcode = =capture_pic) {Options Options=NewOptions (); Options.injustdecodebounds=true;//set decode just to get the width and height values of the picture, instead of actually getting the pictureBitmap Bitmap = Bitmapfactory.decodefile (Imagefilepath, Options);//after decoding can options.outwidth and options.outheight to get the size of the picture                  intWidthRatio = (int) Math.ceil (options.outwidth/width);//gets the compression ratio of the width              intHeightRatio = (int) Math.ceil (options.outheight/height);//get the compression ratio of the height                 if(WidthRatio > 1 | | heightratio > 1) {//as long as one of the ratios is greater than 1, it means that compression is required                  if(Widthratio>=heightratio) {//take options.insamplesize as the maximum value in the width-to-height ratioOptions.insamplesize =WidthRatio; }Else{options.insamplesize=HeightRatio; }} options.injustdecodebounds=false;//set to true decoded pictureBitmap = Bitmapfactory.decodefile (Imagefilepath, Options);//decode PictureImageview.setimagebitmap (bitmap); }            Super. Onactivityresult (Requestcode, ResultCode, data); }         }

Android calls camera to take pictures to get original photos

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.