|
@@ -2,6 +2,7 @@ package com.compdfkit.tools.common.utils;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.database.Cursor;
|
|
import android.database.Cursor;
|
|
|
|
+import android.media.ExifInterface;
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
import android.provider.MediaStore;
|
|
import android.provider.MediaStore;
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
@@ -17,13 +18,13 @@ public class CUriUtil {
|
|
final String[] projection = {column};
|
|
final String[] projection = {column};
|
|
|
|
|
|
try {
|
|
try {
|
|
- cursor = context.getContentResolver().query(uri, projection,null,null,
|
|
|
|
|
|
+ cursor = context.getContentResolver().query(uri, projection, null, null,
|
|
null);
|
|
null);
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
final int column_index = cursor.getColumnIndexOrThrow(column);
|
|
final int column_index = cursor.getColumnIndexOrThrow(column);
|
|
return cursor.getString(column_index);
|
|
return cursor.getString(column_index);
|
|
}
|
|
}
|
|
- }catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
} finally {
|
|
} finally {
|
|
if (cursor != null) {
|
|
if (cursor != null) {
|
|
@@ -33,18 +34,49 @@ public class CUriUtil {
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
- public static String copyUriToInternalCache(Context context, Uri uri){
|
|
|
|
- try{
|
|
|
|
|
|
+ public static String copyUriToInternalCache(Context context, Uri uri) {
|
|
|
|
+ try {
|
|
File file = new File(context.getFilesDir(), CFileUtils.CACHE_FOLDER);
|
|
File file = new File(context.getFilesDir(), CFileUtils.CACHE_FOLDER);
|
|
String fileName = CUriUtil.getUriFileName(context, uri);
|
|
String fileName = CUriUtil.getUriFileName(context, uri);
|
|
- if (TextUtils.isEmpty(fileName)){
|
|
|
|
- fileName = "pic_"+System.currentTimeMillis()+".png";
|
|
|
|
|
|
+ if (TextUtils.isEmpty(fileName)) {
|
|
|
|
+ fileName = "pic_" + System.currentTimeMillis() + ".png";
|
|
}
|
|
}
|
|
String image = CFileUtils.copyImageToInternalDirectory(
|
|
String image = CFileUtils.copyImageToInternalDirectory(
|
|
context, uri, file.getAbsolutePath(), fileName);
|
|
context, uri, file.getAbsolutePath(), fileName);
|
|
return image;
|
|
return image;
|
|
- }catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static int getBitmapDegree(String path) {
|
|
|
|
+ int degree = 0;
|
|
|
|
+ if (TextUtils.isEmpty(path)) {
|
|
|
|
+ return degree;
|
|
|
|
+ }
|
|
|
|
+ try { // 从指定路径下读取图片,并获取其EXIF信息
|
|
|
|
+ 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;
|
|
|
|
+ default:break;
|
|
|
|
+ }
|
|
|
|
+ return degree;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return degree;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|