ImageUtils.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:hypertrack-live-android 作者:
public static Bitmap getRotatedBitMap(File imageFile) {
    if (imageFile == null || !imageFile.canRead() || !imageFile.exists()) {
        return null;
    }

    Bitmap rotatedBitmap = null;

    try {
        Bitmap srcBitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
        ExifInterface exif = new ExifInterface(imageFile.getName());
        String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
        int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL;

        int rotationAngle = 0;
        if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90;
        if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180;
        if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270;

        Matrix matrix = new Matrix();
        matrix.setRotate(rotationAngle, (float) srcBitmap.getWidth() / 2, (float) srcBitmap.getHeight() / 2);
        rotatedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), matrix, true);

    } catch (Exception e) {
        e.printStackTrace();
        CrashlyticsWrapper.log(e);
    }

    return rotatedBitmap;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号