Android 图片旋转
拍照后的照片有时被系统旋转,纠正步骤如下:
1.先读取图片文件被旋转的角度:
/**
* 通过ExifInterface类读取图片文件的被旋转角度
* @param path : 图片文件的路径
* @return 图片文件的被旋转角度
*/
public static int readPicDegree(String path) {
int degree = ; // 读取图片文件信息的类ExifInterface
ExifInterface exif = null;
try {
exif = new ExifInterface(path);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} if (exif != null) {
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = ;
break; case ExifInterface.ORIENTATION_ROTATE_180:
degree = ;
break; case ExifInterface.ORIENTATION_ROTATE_270:
degree = ;
break;
}
} return degree;
}
2.再将上述角度作为参数,传递给下面函数纠正:
/**
* 将图片纠正到正确方向
*
* @param degree : 图片被系统旋转的角度
* @param bitmap : 需纠正方向的图片
* @return 纠向后的图片
*/
public static Bitmap rotateBitmap(int degree, Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.postRotate(degree); Bitmap bm = Bitmap.createBitmap(bitmap, , , bitmap.getWidth(),
bitmap.getHeight(), matrix, true);
return bm;
}
Android 图片旋转的更多相关文章
- Android图片旋转,缩放,位移,倾斜,对称完整示例(一)——imageView.setImageMatrix(matrix)和Matrix
MainActivity如下: import android.os.Bundle; import android.view.MotionEvent; import android.view.View; ...
- android 图片旋转 移动 放大缩小
图片的变化主要是matrix的变化,对matrix不懂的可以先了解下matrxi. public class FunnyView extends View { /* * 手指按下时可能是移动 也可能是 ...
- Android图片旋转,缩放,位移,倾斜,对称完整演示样例(一)——imageView.setImageMatrix(matrix)和Matrix
MainActivity例如以下: import android.os.Bundle; import android.view.MotionEvent; import android.view.Vie ...
- Android 图片旋转(使用Matrix.setRotate方法)
imageView2 = (ImageView) findViewById(R.id.img2); Bitmap bitmap = BitmapFactory.decodeResource(getRe ...
- Android 图片的缩放与旋转
本文实现Android中的图片的缩放效果 首先设计布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res ...
- Android -- 图片处理, 画画板,缩放,旋转,平移,镜面,倒影,图片合成,颜色处理
1. 画画板 示例代码 public class MainActivity extends Activity { private ImageView iv; private Bitmap baseBi ...
- Android提高篇之自定义dialog实现processDialog“正在加载”效果、使用Animation实现图片旋转
知识点: 1.使用imageview.textview自定义dialog 2.使用Animation实现图片旋转动画效果 3.通过自定义theme去掉dialog的title 没有使用progres ...
- Android图片缓存之Bitmap详解
前言: 最近准备研究一下图片缓存框架,基于这个想法觉得还是先了解有关图片缓存的基础知识,今天重点学习一下Bitmap.BitmapFactory这两个类. 图片缓存相关博客地址: Android图片缓 ...
- Android图片处理-图片压缩处理
这里先重复温习一下上一篇,调用相册获取图片: /*** * 这个是调用android内置的intent,来过滤图片文件 ,同时也可以过滤其他的 */ Intent intent = new Inten ...
随机推荐
- Python数据类型之数字
数字(数值) 整数 :123 (int型) 浮点数: 0.25(带小数点的数字即为浮点数,Float型) 布尔值:False,True(即0和1,bool型) 复数 (暂无资料,complex型) 整 ...
- server端获得到client端的IP地址的格式
使用telnet,ping或其他client连接server端时,server端获得的client端的ip地址取决于client端使用的时ipv4还是ipv6地址. 例: client IPv4地址: ...
- Mac下的裁剪快捷键
按[Command]+[C]复制文件,然后按[Command]+[Option]+[V]. 注意:[Command]+[X]只能剪切文字文本.
- MONO MessageBox 类
MessageBox类,负责提示各种消息. using System; using Android.App; using Android.Content; namespace Box { publ ...
- 开源一个Java Class实现Openfire登陆、推出、消息发送,方便其他系统集成IM功能了
开源一个Java Class实现Openfire登陆.推出.消息发送 N年前写的,希望对Openfire开发新手有帮助哦 import java.util.*; import java.io.*; ...
- preg_match 与 preg_match_all
案例一: <?php $str = 'abcdef123456'; preg_match('/[a-z1-9]+/', $str, $res); var_dump($res); preg_mat ...
- AngularJS Eclipse Plugin
本文介绍如何安装和配置 AngularJS Eclipse.AngularJS Eclipse 插件是基于强大的 JavaScript 推断引擎(javascript inference engine ...
- nginx设置开机自启动
每次启动nginx服务都需要到安装目录下的/sbin下面,感觉挺麻烦的. 下面介绍一下如何在Linux(CentOS)系统上,设置nginx开机自启动. 1 用脚本管理nginx服务 第一步:在/et ...
- js脚本语言在页面上不执行
转换原理:// 编码原理就是创建TextNode节点,附加到容器中,再取容器的innerHTML.(将脚本编码) // 解码原理是将字符串赋給容器的innerHTML,再取innerText或text ...
- js中字符串的替换
定义和用法 replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串. 语法 stringObject.replace(regexp/substr,replac ...