正确显示竖屏预览和拍照的照片
2013-09-22 18:38
399 查看
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;
}
http://asysbang.com/forum.php?mod=viewthread&tid=58&extra=page%3D1
主要参考系统相机代码实现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
相关文章推荐
- 正确显示竖屏预览和拍照的照片
- 正确显示竖屏预览和拍照的照片
- v310 拍照发现预览照片时显示异常
- 仿58同城拍照,可连拍多张照片,预览界面中显示所拍的缩略图
- Android自定义相机实现拍照、预览、显示、上传
- 拍照获得的照片,在ImageView中显示时方向有问题的解决方法
- Android 7.0 拍照并显示照片出现"FileUriExposedException"
- android拍照并给照片添加备注,以GridView显示
- 选中照片显示预览 支持IE6 IE7
- android 开发 拍照后显示刚拍的照片
- android Camera摄像头-Surface view 预览拍照 并将拍的照片插入到系统图库
- android 手机拍照上传项目的开发-----Camera1.0(动态显示预览)
- 调用系统相机拍照,保存照片,调用系统裁剪API对照片处理,显示裁剪之后的照片
- 安卓选取多张手机照片同时可以拍照相片然后预览
- Android实现仿微信朋友圈发布动态(拍照、图库选择、照片压缩、显示、保存、缩略图、点击缩略图删除对应文件等)
- PHP 使用 微信JSSDK 拍照选择图片接口 利用localid预览时 安卓手机正常显示 iOS手机不显示
- js上传照片,预览,压缩后base64编码发送后台,及将后台返回的base64图片显示到HTML
- 让PJBlog的首页日志预览正确显示“查看更多”链接
- Android 7.0调用相机拍照,返回后显示拍照照片
- Android 拍照后显示照片