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

原文地址请保留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. Centos配置vsftpd

    #安装vsftpdyum install vsftpd #限制用户只能访问配置的目录,不能访问其他路径#修改vi /etc/vsftpd/vsftpd.conf chroot_list_enable= ...

  2. 使用Xutils 3 中遇到的一些问题!!!!

    1.当xml页面中有可见的,同时设置id的控件时,如果在Activity中没有使用注解进行反射该控件,app会crash,提示:  Caused by: java.lang.NullPointerEx ...

  3. 基于Web Service的客户端框架搭建三:代理层(Proxy)

    前言 代理层的主要工作是调用Web Service,将在FCL层序列化好的Json数据字符串Post到Web Service,然后获得Reponse,再从响应流中读取到调用结果Json字符串,在Dis ...

  4. mybatis JdbcTypeInterceptor - 运行时自动添加 jdbcType 属性

    上代码: package tk.mybatis.plugin; import org.apache.ibatis.executor.ErrorContext; import org.apache.ib ...

  5. 面试:用快排实现数组中的第K大的数

    #include <iostream> #include <cassert> using namespace std; int selectKth(int a[],int st ...

  6. Maven的默认中央仓库

    当构建一个Maven项目时,首先检查pom.xml文件以确定依赖包的下载位置,执行顺序如下: 1.从本地资源库中查找并获得依赖包,如果没有,执行第2步. 2.从Maven默认中央仓库中查找并获得依赖包 ...

  7. Code First, Database First, Same Time区别

    Code First, Database First, Same Time是我理解的asp.net mvc中用到的三种model与数据库对应的方式,肯定是不全面的,理解也有些狭隘,今后随着自己的理解加 ...

  8. php和mysql学习问题笔记

    1.Undefined index: pwd in E:\xampp\htdocs\phpbase2elite\12\source\register.php on line 6 这是一个警告,表示数组 ...

  9. MVC的注意事项及开发技巧

    演示产品源码下载地址:http://www.jinhusns.com 

  10. 出现HTTP 错误 404.0 - Not Found的解决方法

    1.修改配置文件<system.webServer><modules runAllManagedModulesForAllRequests="true" /> ...