由于項目的需要,沒有自定義拍照功能,僅僅調用了系統的拍照程式..但是出現了一個問題,就是拍照完成顯示圖檔居然是被旋轉的圖檔....
解決辦法:
/**
* 擷取圖檔的旋轉角度,有些系統把拍照的圖檔旋轉了,有的沒有旋轉
*/
int degree = readPictureDegree(f.getAbsolutePath());
BitmapFactory.Options opts=new BitmapFactory.Options();//擷取縮略圖顯示到螢幕上 opts.inSampleSize=2;
Bitmap cbitmap=BitmapFactory.decodeFile(f.getAbsolutePath(),opts);
/**
* 把圖檔旋轉為正的方向
*/
Bitmap newbitmap = rotaingImageView(degree, cbitmap);
iv.setImageBitmap(newbitmap);
/** * 讀取圖檔屬性:旋轉的角度 * @param path 圖檔絕對路徑 * @return degree旋轉的角度 */ 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; } /* * 旋轉圖檔 * @param angle * @param bitmap * @return Bitmap */ public static Bitmap rotaingImageView(int angle , Bitmap bitmap) { //旋轉圖檔 動作 Matrix matrix = new Matrix();; matrix.postRotate(angle); System.out.println("angle2=" + angle); // 建立新的圖檔 Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); return resizedBitmap; }