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