今天比较闲(是任务做完了,不是偷懒),就多更新几篇,补一下之前做的东西。

原文地址请保留http://www.cnblogs.com/rossoneri/p/3995306.html

推荐阅读:

Android图片处理:识别图像方向并显示实例教程

android中调用系统相机得到的相片的方向判断

做图片旋转前我考虑了一个问题,就是把android设备反着拿拍照,打开照片的时候是不是反着的。测试后发现,不管我是正着拍照还是倒着拍照,在任何(其实是大部分)设备里的图片浏览器都能把照片正着读出来,所以我就想这个照片里肯定有什么信息,而且是标准信息,来表示照片的正方向。

后来查了资料,发现有这么个玩意:EXIF

有标准,就找接口用就是了。。

另外一个需要知道就就是图像数据旋转怎么搞。

用createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)就好。。

方法说明:

Bitmap android.graphics.Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)

Returns an immutable bitmap from subset of the source bitmap, transformed by the optional matrix. The new bitmap may be the same object as source, or a copy may have been made. It is initialized with the same density as the original bitmap. If the source bitmap is immutable and the requested subset is the same as the source bitmap itself, then the source bitmap is returned and no new bitmap is created.

Parameters:
source The bitmap we are subsetting
x The x coordinate of the first pixel in source
y The y coordinate of the first pixel in source
width The number of pixels in each row
height The number of rows
m Optional matrix to be applied to the pixels
filter true if the source should be filtered. Only applies if the matrix contains more than just translation.
Returns:
A bitmap that represents the specified subset of source
Throws:
IllegalArgumentException - if the x, y, width, height values are outside of the dimensions of the source bitmap.

下面放代码:

读取exif信息,找图片正方向的旋转角度

 private int readPictureDegree(String path) {
int degree = 0;
try {
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;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}

找出角度就旋转吧,让其转回到正方向显示

     private static Bitmap rotate(Bitmap b, int degrees) {
if (degrees == 0) {
return b;
}
if (degrees != 0 && b != null) {
Matrix m = new Matrix();
m.setRotate(degrees, (float) b.getWidth(), (float) b.getHeight());
try {
Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
if (b != b2) {
b.recycle();
b = b2;
}
} catch (OutOfMemoryError ex) {
}
}
return b;
}

这个基本上没问题。。也许有的板子会无法读取到正方向吧。

[Android] 旋转照片/图片的更多相关文章

  1. android的照片浏览器(一)至返回所有图片文件

    今天开始写android的照片浏览器 首先要解决的问题是要得到sdcard下面所有是图片的文件的目录 于是我先写了一个普通的java类 来得到后缀是.jpg,.bmp.png.jpeg的文件 pack ...

  2. Android仿微信图片上传,可以选择多张图片,缩放预览,拍照上传等

    仿照微信,朋友圈分享图片功能 .可以进行图片的多张选择,拍照添加图片,以及进行图片的预览,预览时可以进行缩放,并且可以删除选中状态的图片 .很不错的源码,大家有需要可以下载看看 . 微信 微信 微信 ...

  3. Android旋转动画

    Android旋转动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...

  4. Android开发笔记——图片缓存、手势及OOM分析

    把图片缓存.手势及OOM三个主题放在一起,是因为在Android应用开发过程中,这三个问题经常是联系在一起的.首先,预览大图需要支持手势缩放,旋转,平移等操作:其次,图片在本地需要进行缓存,避免频繁访 ...

  5. Android中读取图片EXIF元数据之metadata-extractor的使用

    一.引言及介绍 近期在开发中用到了metadata-extractor-xxx.jar 和 xmpcore-xxx.jar这个玩意, 索性查阅大量文章了解学习,来分享分享. 本身工作也是常常和处理大图 ...

  6. Android添加背景图片和设置app图标

    Android添加背景图片和设置app图标 Android 添加背景图片 第一步:找到你要当做背景的图片,并下载下来 第二步:将图片复制到app->res->mipmap文件夹下 第三步: ...

  7. android获得ImageView图片的等级

    android获得ImageView图片的等级问题 要实现的功能如下图,点击分享能显示选中与不选中状态,然后发送是根据状态来实现具体分享功能. 在gridview中有5个子项,每个子元素都有两张图片A ...

  8. 解决android:background背景图片被拉伸问题

    ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸.src是图片内容(前 ...

  9. Android  PNG透明图片转JPG格式背景变黑

    Android  PNG透明图片转JPG格式背景变黑 在上传图片是,需要把PNG格式转换成JPG格式的,但是在遇上透明背景时,转过来就变成黑色底图了! 原因是PNG支持透明图而 JPG格式不支持透明底 ...

随机推荐

  1. postgresql 导出和导入数据库

    使用 pg_dump 和 pg_restore 来备份和还原 postgresql的数据: 导出:pg_dump导入:pg_restore 最简单的导出命令如下:(导出指定数据库) $ pg_dump ...

  2. Ansible中playbook的变量

    转自:http://www.cnblogs.com/lemon-le/p/6862788.html 先看看debug模块的使用: msg:输出调试信息 var:将某个任务执行的输出作为变量传给debu ...

  3. 【IT笔试面试题整理】有序数组生成最小高度二叉树

    [试题描述]定义一个函数,输入一个有序数组生成最小高度二叉树 We will try to create a binary tree such that for each node, the numb ...

  4. spring配置文件引入properties文件:<context:property-placeholder>标签使用总结

    一.问题描述: 1.有些参数在某些阶段中是常量,比如: (1)在开发阶段我们连接数据库时的连接url.username.password.driverClass等 (2)分布式应用中client端访问 ...

  5. webpack4 自学笔记一(babel的配置)

    所有代码都可以再我的github上查看,每个文件夹下都会有README.md,欢迎star: https://github.com/Jasonwang911/webpackStudyInit/tree ...

  6. APP---发布动态、朋友圈类似,多张图片动响应式正方形展示布局 vue.js,aui.css,apiclouv

    环境:vue.js,aui.css,apicloud 1.没做控制之前.图片真实长度宽度. 2.下面用js控制高度 js部分 //js 部分 //先动态的获取属性宽度 var box4_col3 = ...

  7. MVC应用程序显示RealPlayer(rm)视频

    本篇博文是演示MVC应用程序显示RealPlayer视频. 客户端能观看到RealPlayer视频,前提条件是需要安装RealPlayer客户端,就是想看Falsh或理WMV视频一样,均要安装客户端或 ...

  8. Cannot find module 'socket.io'

    That's all. Then I try to use socket.io with this line: var io = require('socket.io').listen(app); A ...

  9. JavaSE 集合补充点(JDK1.9对集合添加的优化)

    通常,我们在代码中创建一个集合(例如,List 或 Set ),并直接用一些元素填充它. 实例化集合,几个 add方法调用,使得代码重复. public class Demo01 { public s ...

  10. Training little cats(poj3735,矩阵快速幂)

    Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10737   Accepted:  ...