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