Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/net/tsz/afinal/bitmap/core/BitmapProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public Bitmap getBitmap(String url, BitmapDisplayConfig config) {
}
}

if (url.trim().toLowerCase().startsWith("file:")) {// 旋转图片
int degree = Utils.getDegree(url.replace("file://", ""));
if (degree != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(degree);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
}

return bitmap;
}

Expand Down
32 changes: 31 additions & 1 deletion src/net/tsz/afinal/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,37 @@ public static File getDiskCacheDir(Context context, String uniqueName) {
return new File(cachePath + File.separator + uniqueName);
}


/** 计算图片旋转角度
* @param uri
* @return */
public static int getDegree(String uri) {
int degree = 0;
ExifInterface exif = null;
try {
exif = new ExifInterface(uri);
} catch (IOException e) {
e.printStackTrace();
exif = null;
}
if (exif != null) {
int ori = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);// 读取图片中相机方向信息
switch (ori) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
default:
degree = 0;
break;
}
}
return degree;
}

/**
* 获取bitmap的字节大小
Expand Down