栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

拍摄人像时Android相机意图保存图像风景

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

拍摄人像时Android相机意图保存图像风景

照片始终以相机内置在设备中的方向拍摄。为了使图像正确旋转,您必须读取存储在图片中的方向信息(EXIF元数据)。在那里存储了拍摄图像时设备的方向。

这是一些读取EXIF数据并相应旋转图像的代码:

file
是图像文件的名称。

BitmapFactory.Options bounds = new BitmapFactory.Options();bounds.inJustDepreBounds = true;BitmapFactory.depreFile(file, bounds);BitmapFactory.Options opts = new BitmapFactory.Options();Bitmap bm = BitmapFactory.depreFile(file, opts);ExifInterface exif = new ExifInterface(file);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) bm.getWidth() / 2, (float) bm.getHeight() / 2);Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true);

更新2017-01-16

随着25.1.0支持库的发布,引入了ExifInterface支持库,这也许应该使对Exif属性的访问更容易。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/365186.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号