Private Static Final intPhoto_request_takephoto = 1;//Take Pictures Private Static Final intPhoto_request_gallery = 2;//Select from the album Private Static Final intPhoto_request_cut = 3;//Results PrivateFile tempfile =NewFile (Environment.getexternalstoragedirectory (), Getphotofilename ()); protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { Switch(requestcode) { CasePhoto_request_takephoto://called when you choose to take a photoStartphotozoom (Uri.fromfile (tempfile)); Break; CasePhoto_request_gallery://When you choose to get pictures from local//do non-empty judgment, when we feel dissatisfied want to re-cut the time will not report abnormal, the same if(Data! =NULL) {System.out.println ("11================"); Startphotozoom (Data.getdata ()); } Else{System.out.println ("================"); } Break; CasePhoto_request_cut://The returned result if(Data! =NULL) //Setpictoview (data);sentpictonext (data); Break; } Super. Onactivityresult (Requestcode, ResultCode, data); }
// use the system's current date to adjust the name of the photo Private String Getphotofilename () { new Date (System.currenttimemillis ()); New SimpleDateFormat ( "' IMG ' _yyyymmdd_hhmmss"); return Dateformat.format (date) + ". jpg"; }
Call System Photo function:
New Intent ( mediastore.action_image_capture); // Specifies the storage path of the photo after the camera is called Cameraintent.putextra (mediastore.extra_output, uri.fromfile (tempfile)); Startactivityforresult (cameraintent, photo_request_takephoto);
Call System album features:
New Intent (intent.action_get_content); Getalbum.settype ("image/*"); Startactivityforresult (Getalbum, photo_request_gallery);
To invoke the system cropping feature:
Private voidstartphotozoom (Uri uri) {Intent Intent=NewIntent ("Com.android.camera.action.CROP"); Intent.setdataandtype (URI,"Image/*"); //crop True is set to set the displayed view in the open intent can be clippedIntent.putextra ("Crop", "true"); //Aspectx Aspecty is the ratio of width to heightIntent.putextra ("Aspectx", 1); Intent.putextra ("Aspecty", 1); //Outputx,outputy is the width height of the cropped pictureIntent.putextra ("Outputx", 300); Intent.putextra ("Outputy", 300); Intent.putextra ("Return-data",true); Intent.putextra ("Nofacedetection",true); System.out.println ("22================"); Startactivityforresult (Intent, photo_request_cut); }
Customize dialog box:
New Alertdialog.builder (this, R.style.fullscreendialog) . Create (); if NULL &&! mdialog.isshowing ()) { mdialog.show (); Mdialog.setcontentview (R.LAYOUT.DIALOG_SELECT_IMGE); Mdialog.setcanceledontouchoutside (false);
}
Custom style:
<stylename= "Fullscreendialog"Parent= "Android:style/theme.dialog"> <Itemname= "Android:windownotitle">True</Item> <Itemname= "Android:windowframe">@null</Item> <Itemname= "Android:windowisfloating">True</Item> <Itemname= "Android:windowistranslucent">False</Item> <Itemname= "Android:background">@android: Color/transparent</Item> <Itemname= "Android:windowbackground">@android: Color/transparent</Item> <Itemname= "android:backgrounddimenabled">True</Item> </style>
[Android Pro] Call system camera and gallery, crop picture