Private URI Uri;
Photo
Intent Getimagebycamera = new Intent ("Android.media.action.IMAGE_CAPTURE");
Contentvalues values = new Contentvalues ();
Values.put (MediaStore.Images.Media.DISPLAY_NAME, String.valueof (System.currenttimemillis ()) + ". jpg");
Values.put (MediaStore.Images.Media.MIME_TYPE, "image/png");
URI = Getcontentresolver (). Insert (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Getimagebycamera.putextra (MediaStore.Images.Media.ORIENTATION, 0);
Getimagebycamera.putextra (Mediastore.extra_output, URI);
Startactivityforresult (Getimagebycamera,request_camera);
Get pictures of photos
if (Requestcode = = Request_camera) {//Camera get Photos
String Path = Tool.getpathfromuri (context, URI);
int orientation = tool.readpicturedegree (path);//Get rotation angle
APPLOG.D ("Dingdongkai", "orientation===" +orientation);
if (Math.Abs (orientation) > 0) {
Bitmap bit = Getbitmapfromuri (URI);
Bitmap = Tool.rotaingimageview (orientation, bit);//Rotate Picture
}
Startphotozoom (Uri.parse (MediaStore.Images.Media.insertImage (Getcontentresolver (), Bitmap, null,null));
Get picture path based on URI
public static String Getpathfromuri (Context Mcontext,uri Contenturi) {
APPLOG.D ("Dingdongkai", "contenturi===" +contenturi.tostring ());
String[] proj = {MediaStore.Images.Media.DATA};
Cursorloader loader = new Cursorloader (Mcontext, Contenturi, proj, NULL, NULL, NULL);
cursor cursor = Loader.loadinbackground ();
int column_index = Cursor.getcolumnindexorthrow (MediaStore.Images.Media.DATA);
Cursor.movetofirst ();
Return cursor.getstring (Column_index);
}
Get the rotation angle of the picture
public static int Readpicturedegree (String path) {
int degree = 0;
try {
Exifinterface exifinterface = new Exifinterface (path);
int orientation = Exifinterface.getattributeint (exifinterface.tag_orientation, exifinterface.orientation_normal);
Switch (orientation) {
Case EXIFINTERFACE.ORIENTATION_ROTATE_90:
degree = 90;
Break
Case EXIFINTERFACE.ORIENTATION_ROTATE_180:
degree = 180;
Break
Case EXIFINTERFACE.ORIENTATION_ROTATE_270:
degree = 270;
Break
}
} catch (IOException e) {
E.printstacktrace ();
}
return degree;
}
/**
* Crop Image Method implementation
*
* @param URI
*/
public void Startphotozoom (Uri uri) {
Set crop properties
Intent Intent = new Intent ("Com.android.camera.action.CROP");
Intent.setdataandtype (URI, "image/*");
Intent.putextra ("Crop", "true");
Intent.putextra ("Aspectx", 1);
Intent.putextra ("Aspecty", 1);
Intent.putextra ("Outputx", 320);
Intent.putextra ("Outputy", 320);
Intent.putextra ("Return-data", true);
Startactivityforresult (Intent, 6);
}
Solve the camera photo is not clear, photo rotation problem!