正确显示竖屏预览和拍照的照片
来源:互联网 发布:网络图片可爱搞笑 编辑:程序博客网 时间:2024/04/29 05:47
1、预览时正确显示
主要参考系统相机代码实现getDisplayOritation就可以了
//在preview之前调用setDisplayOrientation
int degrees = getDisplayOritation(getDispalyRotation(), cameraId);
mCamera.setDisplayOrientation(degrees);
mCamera.startPreview();
getDisplayOritation函数如下:
private int getDisplayOritation(int degrees, int cameraId) {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360;
} else {
result = (info.orientation - degrees + 360) % 360;
}
return result;
}
private int getDispalyRotation() {
int i = getWindowManager().getDefaultDisplay().getRotation();
switch (i) {
case Surface.ROTATION_0:
return 0;
case Surface.ROTATION_90:
return 90;
case Surface.ROTATION_180:
return 180;
case Surface.ROTATION_270:
return 270;
}
return 0;
}
2、显示图片时正确显示
竖屏拍照的照片,直接使用的话,会旋转90度
参考系统图库的代码,需要先查询mediascanner的orientation字段,然后应用再把角度旋转过来,这样显示就ok了
参考代码如下:
假设c为查询mediaprovider数据库返回的cursor
int rotation = c.getInt(c.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
if (rotation != 0) {
Bitmap bitmap = BitmapFactory.decodeFile(path);
imageBefore.setImageBitmap(bitmap);
Matrix m = new Matrix();
m.setRotate(rotation);
Bitmap transformed = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
return transformed;
主要参考系统相机代码实现getDisplayOritation就可以了
//在preview之前调用setDisplayOrientation
int degrees = getDisplayOritation(getDispalyRotation(), cameraId);
mCamera.setDisplayOrientation(degrees);
mCamera.startPreview();
getDisplayOritation函数如下:
private int getDisplayOritation(int degrees, int cameraId) {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360;
} else {
result = (info.orientation - degrees + 360) % 360;
}
return result;
}
private int getDispalyRotation() {
int i = getWindowManager().getDefaultDisplay().getRotation();
switch (i) {
case Surface.ROTATION_0:
return 0;
case Surface.ROTATION_90:
return 90;
case Surface.ROTATION_180:
return 180;
case Surface.ROTATION_270:
return 270;
}
return 0;
}
2、显示图片时正确显示
竖屏拍照的照片,直接使用的话,会旋转90度
参考系统图库的代码,需要先查询mediascanner的orientation字段,然后应用再把角度旋转过来,这样显示就ok了
参考代码如下:
假设c为查询mediaprovider数据库返回的cursor
int rotation = c.getInt(c.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
if (rotation != 0) {
Bitmap bitmap = BitmapFactory.decodeFile(path);
imageBefore.setImageBitmap(bitmap);
Matrix m = new Matrix();
m.setRotate(rotation);
Bitmap transformed = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
return transformed;
}
http://asysbang.com/forum.php?mod=viewthread&tid=58&extra=page%3D1
- 正确显示竖屏预览和拍照的照片
- 正确显示竖屏预览和拍照的照片
- 正确显示竖屏预览和拍照的照片
- Android拍照后显示照片
- Android 拍照后显示照片
- android 开发 拍照后显示刚拍的照片
- Android高仿微信照片选择器+预览+显示照片
- android Camera摄像头-Surface view 预览拍照 并将拍的照片插入到系统图库
- iOS 上传照片到服务器 获取相册和拍照功能的照片 照片压缩上传
- 获取相册照片和获取拍照照片
- 获取本地照片和拍照上传并裁剪的实现
- 拍照和进去相册选照片的问题
- PDF的显示和预览
- Android拍照 图库照片本地显示
- Android 拍照,选取照片,截取,显示
- Android 7.0调用相机拍照,返回后显示拍照照片
- 调用手机摄像头拍照和从图库中选取照片以及得到照片后的备份
- android拍照和选择照片(单张)出现照片无法加载的问题
- 婚姻法律
- 说话是一门艺术 处事是一门学问
- java---金字塔
- 科来Mac地址扫描器无法扫描问题
- vs2012 编译jsoncpp和使用jsoncpp lib出现的问题
- 正确显示竖屏预览和拍照的照片
- 关于jsoncpp内部排序的问题
- C++中基类的析构函数为什么要用virtual虚析构函数
- IE浏览器条件注释
- ArcGIS10.1 Desktop打开慢的问题
- 李白喝酒问题Java编程
- VC编译选项/MT/MTd/MD/MDd说明
- js正在判断ip
- Android开发服务器的搭建