Photo + photo Album + Image Capture

Source: Internet
Author: User
Tags call back

First, photo + intercept

Photo:

 Mstoragedir = environment.getexternalstoragepublicdirectory (ENVIRONMENT.DIRECTORY_DCIM); //  Get the area of the memory dedicated to the picture  URI = uri.fromfile ( New  File (Mstoragedir.getpath () +system.currenttimemillis () + ". png")); //  Intent Intent = new   Intent (mediastore.action_                Image_capture);  //  pass the picture-processed data to the URI   Intent.putextra (Mediastore.extra_output,uri);  //  (Activity) mcontext). Startactivityforresult (Intent,requst_photo); 
Take Pictures

Callback after the photo is finished

Activity.onactivityresult ()

if(Requestcode = =Imagedialog.requst_photo) {     //capturing a picture the first parameter is just the URI.Cropimageuri (imagedialog.uri,800,600, Requst_crap);}Private voidCropimageuri (Uri Uri,intOUTPUTX,intOutputy,intRequestcode) {Intent Intent=NewIntent ("Com.android.camera.action.CROP"); Intent.setdataandtype (URI,"Image/*"); Intent.putextra ("Crop", "true"); Intent.putextra ("Aspectx", 2); Intent.putextra ("Aspecty", 1); Intent.putextra ("Outputx", OUTPUTX); Intent.putextra ("Outputy", outputy); Intent.putextra ("Scale",true);        Intent.putextra (Mediastore.extra_output, URI); Intent.putextra ("Return-data",false); Intent.putextra ("OutputFormat", Bitmap.CompressFormat.JPEG.toString ()); Intent.putextra ("Nofacedetection",true);//No Face Detection//You 'll need to call back once you've finished capturing the picture.Startactivityforresult (Intent, Requestcode); }
View Code

Save the picture from Onactivityresult () to the address

Else if(Requestcode = =requst_crap) {Bitmap Bitmap=Decodeuriasbitmap (Data.getdata ());    Imageview.setimagebitmap (bitmap); }PrivateBitmap decodeuriasbitmap (Uri uri) {Bitmap photo=NULL; Uri Photouri=URI; if(Photouri! =NULL) {            //get bitmap based on URI addressPhoto =Bitmapfactory.decodefile (Photouri.getpath ());        } log.d (Tag,photouri.getpath ()); if(Photo = =NULL) {            //Create a JPEG imageBytearrayoutputstream stream =NewBytearrayoutputstream (); Photo.compress (Bitmap.CompressFormat.JPEG,100, stream); }        returnphoto; }
View Code

Second, select from the album + Intercept

Intent Intent =NewIntent (Intent.action_get_content,NULL); //indicates that the selected image typeIntent.settype ("image/*"); Intent.putextra ("Crop", "true"); //Percentage of interceptionIntent.putextra ("Aspectx", 2); Intent.putextra ("Aspecty", 1); //pixels of outputIntent.putextra ("Outputx", 600); Intent.putextra ("Outputy", 300); Intent.putextra ("Scale",true); Intent.putextra ("Return-data",false);                Intent.putextra (Mediastore.extra_output, URI); Intent.putextra ("OutputFormat", Bitmap.CompressFormat.JPEG.toString ()); Intent.putextra ("Nofacedetection",true);//No Face Detection( Activity) mcontext). Startactivityforresult (Intent, request_gallery); 
View Code

The next steps are the same as above

Photo + photo Album + Image Capture

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.