通過絕對路徑生成bitmap圖片並覈對圖片方向

/**
     * @author yukaida
     * @param absolutePath 照片的絕對路勁
     * @return 重新調整方向之後的bitmap圖片
     */
    public static Bitmap orientation(String absolutePath){
        Bitmap bitmap_or=BitmapFactory.decodeFile(absolutePath);
     try {

        ExifInterface exif = new ExifInterface(absolutePath);

        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

        Log.d("EXIF", "Exif: " + orientation);

        Matrix matrix = new Matrix();

        if (orientation == 6) {

            matrix.postRotate(90);

        }

        else if (orientation == 3) {

            matrix.postRotate(180);

        }

        else if (orientation == 8) {

            matrix.postRotate(270);

        }

         bitmap_or= Bitmap.createBitmap(bitmap_or, 0, 0, bitmap_or.getWidth(), bitmap_or.getHeight(), matrix, true); // rotating bitmap
         return bitmap_or;
    }

            catch (Exception e) {

    }
        return null;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章