Once you've taken your Android photo, cut the picture one at a time and save the picture to the specified directory. After the project requires the user to take a photo and cut the picture, it is sent to the server side for verification. A small example is posted here to enable basic functionality. The article will be shown at the end of the demo. The interface is a click event.
1. First click on the event to start the photo, here to write the name of the dead picture. You can actually operate by defining a static variable in a common class.
public void Tackphoto () {String status = Environment.getexternalstoragestate (); if (Status.equals (Environment.media_ Mounted) {try {File FilePath = Environment.getexternalstoragedirectory (); Intent Intent = new Intent ( Android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File F = new file (FilePath, "test.jpg"); Uri u = uri.fromfile (f); Intent.putextra (MediaStore.Images.Media.ORIENTATION, 0); Intent.putextra (Mediastore.extra_ OUTPUT, u); Startactivityforresult (Intent, flag_choose_phone);} catch (Activitynotfoundexception e) {e.printstacktrace ();}}}
2. Get the value in the Onactivityresult method
@Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {if (resultcod E = = result_ok) {File FilePath = Environment.getexternalstoragedirectory (); File F = new file (FilePath, "test.jpg"); if (Requestcode = = Flag_choose_phone) {Toast. Maketext (This, "Flag_choose_phone", Toast.length_sh ORT). Show (); String path = F.getabsolutepath (); Intent Intent = new Intent (); Intent.setaction ("Com.android.camera.action.CROP"); Intent.setdataandtype (URI. FromFile (NewFile (path)), "image/*");//Muri is an already selected picture Uri intent.putextr A ("Crop", "true"); Intent.putextra ("Aspectx", 3); Cropping frame proportional Intent.putextra ("Aspecty", 3); Intent.putextra ("Outputx", 150); Output pictureSize Intent.putextra ("Outputy", 150); Intent.putextra ("Return-data", true); Startactivityforresult (Intent,flag_crop_phone); } else if (Requestcode = = Flag_crop_phone) {Bitmap bmap = Data.getparcelableextra ("Data"); if (bmap! = null) {try {Bmap.compres S (Bitmap.compressformat. JPEG, 0, Newfileoutputstream (f)); } catch (FileNotFoundException e) {e.printstacktrace (); } } } } }3. Finally, to add some permissions
< uses-permission Android:name = "Android.permission.CAMERA"/><uses-permission android:name= " Android.permission.WRITE_EXTERNAL_STORAGE "/>
: http://www.oschina.net/action/code/download?code=44069&id=61639
Android photo, cut, and put into SD card