Due to the needs of the project, there is no custom camera function, just call the system's camera program. But there is a problem, that is, the photo is finished to show the picture is actually rotated pictures ....
Workaround:
/**
* Get the rotation angle of the picture, some systems rotate the picture taken, and some do not rotate
*/
Int degree = readPictureDegree(f.getAbsolutePath());
BitmapFactory.Options opts=new BitmapFactory.Options();//Get the thumbnail display to the screen opts.inSampleSize=2;
Bitmap cbitmap=BitmapFactory.decodeFile(f.getAbsolutePath(),opts);
/**
* Rotate the picture to a positive direction
*/
Bitmap newbitmap = rotaingImageView(degree, cbitmap);
iv.setImageBitmap(newbitmap);
/** * Read image properties: angle of rotation
* @param path image absolute path
* @return degree angle of rotation
*/
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;
}
/* * Rotate image * @param angle * @param bitmap * @return Bitmap */
Public static Bitmap rotaingImageView(int angle , Bitmap bitmap) { //Rotate the image Action
Matrix matrix = new Matrix();;
matrix.postRotate(angle);
System.out.println("angle2=" + angle);
// Create a new image
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
Return resizedBitmap;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
About Android in the call system to take pictures, the return picture is rotated 90 degrees.