Tim*_*mmm 8 android uri exif stream orientation
我正在编写一个可以从Android的"分享通过"菜单中发送照片URI的应用.
时获得的URI的是content://media/external/images/media/556但是ExifInterface想要一个标准的文件名.那么如何读取该文件的exif数据(我只想要方向)?这是我的(非工作)代码:
Uri uri = (Uri)extras.getParcelable(Intent.EXTRA_STREAM);
ContentResolver cr = getContentResolver();
InputStream is = cr.openInputStream(uri);
Bitmap bm = BitmapFactory.decodeStream(is);
// This line doesn't work:
ExifInterface exif = new ExifInterface(uri.toString());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Run Code Online (Sandbox Code Playgroud)
任何帮助(除了"你必须编写自己的ExifInterface类")表示赞赏!
Tim*_*mmm 16
我在Facebook Android SDK示例中随机找到了答案.我没有测试过它,但它看起来应该可行.这是代码:
public static int getOrientation(Context context, Uri photoUri) {
/* it's on the external media. */
Cursor cursor = context.getContentResolver().query(photoUri,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
int result = -1;
if (null != cursor) {
if (cursor.moveToFirst()) {
result = cursor.getInt(0);
}
cursor.close();
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9103 次 |
| 最近记录: |