通过绝对路径生成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;
    }
发布了39 篇原创文章 · 获赞 15 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_29478763/article/details/103213087