ImageView支持Exif
来源:互联网 发布:淘宝买零食吃靠谱吗 编辑:程序博客网 时间:2024/06/06 03:04
ImageView支持Exif
什么是Exif
可交换图像文件格式,简称为Exif(Exchangeable image file format)。是专门为数码相机的照片设定的,可以记录数码照片的属性信息和拍摄数据。
exif中包含图片的方向信息,这个是本文讨论的重点。exif orientation详细介绍
链接中的orientation value,0th row,0th column的关系换成下图更好理解:
可以用手机拍摄一张图片,在这个网站查看exif。
Camera Sensor方向
图像传感器(Image Sensor),是有默认的取景方向的。Android Image Sensor取景方向如图所示:
Android Camera Sensor采集图像数据都是这个视角。所以,手机旋转90°拍摄的图片放在电脑上显示的图像并不是正的。
为什么手机相册显示的图片却是正的?
因为相册app有对图片进行处理。简单来说原理就是,获取exif中的orientation信息,然后将图片旋转相应角度。
ImageView 支持exif orientation
获取图片exif,然后取得旋转角度,将图片旋转相应角度后给ImageView显示。
private class DisplayTask implements Runnable { @Override public void run() { try { InputStream in = getAssets().open("pic.jpg"); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(getStream(in), null, options); options.inSampleSize = caculateInSampleSize(options, imageView.getMeasuredWidth(), imageView.getMeasuredHeight()); options.inJustDecodeBounds = false; Bitmap bmp = BitmapFactory.decodeStream(getStream(in), null, options); int degree=0; switch (getImageOrientation(getStream(in))){ case android.media.ExifInterface.ORIENTATION_ROTATE_90: degree=90; break; case android.media.ExifInterface.ORIENTATION_ROTATE_180: degree=180; break; case android.media.ExifInterface.ORIENTATION_ROTATE_270: degree=270; break; } //旋转图片 Matrix matrix=new Matrix(); matrix.postRotate(degree); Bitmap finalBmp=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,true); //居中 matrix.reset(); matrix.postTranslate((imageView.getMeasuredWidth()-finalBmp.getWidth())/2,(imageView.getMeasuredHeight()-finalBmp.getHeight())/2); imageView.setImageMatrix(matrix); imageView.setImageBitmap(finalBmp); } catch (IOException e) { e.printStackTrace(); } }}
完整代码
下载链接
阅读全文
0 0
- ImageView支持Exif
- exif
- EXIF
- 支持GIF动画的ImageView
- 支持GIF动画的ImageView
- 支持手势缩放的ImageView
- 支持手势缩放的ImageView
- 支持手势缩放的ImageView
- 自定义支持缩放的ImageView
- 支持手势缩放的ImageView
- 支持手势缩放的ImageView 仅供参考
- 支持滚动展示图片的ImageView
- 支持滚动展示图片的ImageView
- 支持拖拽、缩放的ImageView
- CustomImageView圆形imageView, 支持xutils加载
- java复制图片EXIF信息(支持jpeg格式),使用了MediaUtils
- 什么是 EXIF
- EXif address
- 机器学习中的各种距离
- Java技术学习路线思路
- H265(HEVC)视频下载 测试专用
- BZOJ 3170 [Tjoi 2013]松鼠聚会 切比雪夫距离-->曼哈顿距离
- Vue.js中的图片引用路径
- ImageView支持Exif
- leetcode Search a 2D Matrix II
- 使用heat创建虚拟机
- Qt--03:信号与槽
- jquery的ajax和getJson跨域获取json数据的实现方法
- Burp Suite is one of the best tools available for web application testing. Its wide variety of featu
- Jenkins插件下载失败两种处理办法
- vue滚动自动加载
- 线性探测再散列和平方探测再散列(二次探测再散列)算法