三星手机拍照旋转问题 调用相机 拍照出现横竖屏切换?
拍照获取图片时,当应用是竖屏时,在部分手机上,如:三星note3上,图片不能正常显示,会旋转90°。
=_=
大概的思路就是拍照后获取图片旋转的角度,然后再回转同样的角度,一般均为0
1.调用拍照后,读取临时存储的图片,temp为自定义的路径
调用拍照
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//下面这句指定调用相机拍照后的照片存储的路径intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(),SQConstants.tempImgFile)));// SQConstants.tempImgFile文件名public static final String tempImgFile = "/avatar.png";//intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);//intent.putExtra("return-data", true);startActivityForResult(intent, SQConstants.AVATAR_CAMERA);//SQConstants.AVATAR_CAMERA为常量值,在返回activity时使用,可自行定义
读取图片Bitmap bm = BitmapsUtil.decodeFile(temp, 100);
private static final int DEFAULT_REQUIRED_SIZE = 70;public static Bitmap decodeFile(File f, int size) {try {BitmapFactory.Options option = new BitmapFactory.Options();/**inJustDecodeBounds如果将其设为true的话,在decode时将会返回null。通过此设置可以去查询一个bitmap的属性,比如bitmap的长和宽,而不占用内存大小.同时可避免OOM*/option.inJustDecodeBounds = true;FileInputStream stream1 = new FileInputStream(f);BitmapFactory.decodeStream(stream1, null, option);stream1.close();final int REQUIRED_SIZE = size > 0 ? size : DEFAULT_REQUIRED_SIZE;int width_tmp = option.outWidth, height_tmp = option.outHeight;int scale = 1;while (true) {if (width_tmp / 2 < REQUIRED_SIZE|| height_tmp / 2 < REQUIRED_SIZE)break;width_tmp /= 2;height_tmp /= 2;scale *= 2;}if (scale >= 2) {scale /= 2;}BitmapFactory.Options option2 = new BitmapFactory.Options();option2.inSampleSize = scale;FileInputStream stream2 = new FileInputStream(f);Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, option2);stream2.close();return bitmap;} catch (FileNotFoundException e) {} catch (IOException e) {e.printStackTrace();}return null;}
2.获取图片旋转的角度,然后给它旋转回来
int degree = BitmapsUtil.readPictureDegree(temp.getAbsolutePath());
/*** 获取图片信息* * @param path* @return*/public static 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;}
3.根据指定旋转度数进行图片旋转
Bitmap bitmap = BitmapsUtil.rotaingImageView(degree, bm);
/*** 图片旋转* * @param angle* @param bitmap* @return*/public static Bitmap rotaingImageView(int angle, Bitmap bitmap) {// 旋转图片 动作Matrix matrix = new Matrix();matrix.postRotate(angle);System.out.println("angle=" + angle);// 创建新的图片Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,bitmap.getWidth(), bitmap.getHeight(), matrix, true);return resizedBitmap;}
4.存储旋转后图片
compressHeadPhoto(bitmap);
private File rotateFile;private void compressHeadPhoto(final Bitmap bm) {rotateFile = new File(Environment.getExternalStorageDirectory(),"rotate.png");try {press(pressFormat.PNG, 70, new FileOutputStream(rotateFile));} catch (FileNotFoundException e) {e.printStackTrace();}}
5.调用图片裁切
startPhotoZoom(Uri.fromFile(rotateFile));
/*** 裁剪图片方法实现* @param uri*/public void startPhotoZoom(Uri uri) {Logs.i("startPhotoZoom uri: " + uri);/** 至于下面这个Intent的ACTION是怎么知道的,大家可以看下自己路径下的如下网页* yourself_sdk_path/docs/reference/android/content/Intent.html* 直接在里面 Ctrl+F 搜:CROP **/Intent intent = new Intent("com.android.camera.action.CROP");intent.setDataAndType(uri, "image/*");//下面这个crop=true是设置在开启的Intent中设置显示的view可裁剪intent.putExtra("crop", "true");// aspectX aspectY 是宽高的比例intent.putExtra("aspectX", 1);intent.putExtra("aspectY", 1);// outputX outputY 是裁剪图片宽高intent.putExtra("outputX", 150);intent.putExtra("outputY", 150);intent.putExtra("return-data", true);startActivityForResult(intent, SQConstants.AVATAR_C_A_DATA_IMG);}
Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键
快捷键
加粗Ctrl + B
斜体Ctrl + I
引用Ctrl + Q
插入链接Ctrl + L
插入代码Ctrl + K
插入图片Ctrl + G
提升标题Ctrl + H
有序列表Ctrl + O
无序列表Ctrl + U
横线Ctrl + R
撤销Ctrl + Z
重做Ctrl + Y
Markdown及扩展
Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,然后转换成格式丰富的HTML页面。 —— [ 维基百科 ]
使用简单的符号标识不同的标题,将某些文字标记为粗体或者斜体,创建一个链接等,详细语法参考帮助?。
本编辑器支持Markdown Extra, 扩展了很多好用的功能。具体请参考Github.
表格
MarkdownExtra表格语法:
可以使用冒号来定义对齐方式:
定义列表
MarkdownExtra定义列表语法: 项目1 项目2 定义 A 定义 B 项目3 定义 C定义 D
定义D内容
代码块
代码块语法遵循标准markdown代码,例如:
@requires_authorizationdef somefunc(param1='', param2=0):'''A docstring'''if param1 > param2: # interestingprint 'Greater'return (param2 - param1 + 1) or Noneclass SomeClass:pass>>> message = '''interpreter... prompt'''
脚注
生成一个脚注1.
目录
用[TOC]
来生成目录:
三星手机拍照旋转问题 调用相机 拍照出现横竖屏切换 快捷键Markdown及扩展 表格定义列表代码块脚注目录数学公式UML 图 离线写博客浏览器兼容
数学公式
使用MathJax渲染LaTex数学公式,详见.
行内公式,数学公式为: Γ(n)=(n−1)!∀n∈N 。块级公式: x=−b±b2−4ac−−−−−−−√2a
更多LaTex语法请参考 这儿.
UML 图:
可以渲染序列图:
或者流程图:
关于序列图语法,参考 这儿,关于流程图语法,参考 这儿.
离线写博客
即使用户在没有网络的情况下,也可以通过本编辑器离线写博客(直接在曾经使用过的浏览器中输入write./mdeditor即可。Markdown编辑器使用浏览器离线存储将内容保存在本地。
用户写博客的过程中,内容实时保存在浏览器缓存中,在用户关闭浏览器或者其它异常情况下,内容不会丢失。用户再次打开浏览器时,会显示上次用户正在编辑的没有发表的内容。
博客发表后,本地缓存将被删除。
用户可以选择把正在写的博客保存到服务器草稿箱,即使换浏览器或者清除缓存,内容也不会丢失。
注意:虽然浏览器存储大部分时候都比较可靠,但为了您的数据安全,在联网后,请务必及时发表或者保存到服务器草稿箱。
浏览器兼容
目前,本编辑器对Chrome浏览器支持最为完整。建议大家使用较新版本的Chrome。IE9以下不支持IE9,10,11存在以下问题不支持离线功能IE9不支持文件导入导出IE10不支持拖拽文件导入这里是脚注的内容. ↩