1. 程式人生 > >Android系統攝像機顯示逆時針反轉90度解決方案

Android系統攝像機顯示逆時針反轉90度解決方案

因為本人手機是三星,每次拍照顯示後的圖片都是逆時針反轉90度的,所以找了解決辦法,親測已解決

/**
     * 讀取照片exif資訊中的旋轉角度
     *
     * @param path 照片路徑
     * @return角度
     */
    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; } public static Bitmap Toturn(Bitmap img) { Matrix matrix = new
Matrix();         matrix.postRotate(+90); int width = img.getWidth(); int height = img.getHeight(); img = Bitmap.createBitmap(img, 0, 0, width, height, matrix, true); return img; }

記得呼叫方法。

	//獲取bitmap
        //Bitmap bitmap = getZipImageBitmap(imageView);  
        Bitmap bitmap = Toturn(getZipImageBitmap(imageView));
        imageView.setImageDrawable(new BitmapDrawable(bitmap));
        readPictureDegree(path);//path是儲存圖片的路徑
這樣就解決了會逆時針翻轉的問題了