根据文档,设置旋转(90) http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setRotation%28int%29应旋转捕获的 JPEG 图片(拍照片 http://developer.android.com/reference/android/hardware/Camera.html#takePicture%28android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback%29在横向模式下。
这在 HTC 手机上运行良好,但不适用于三星 Google Nexus S 和三星 Galaxy S3。这是一个错误吗?
我知道我可以使用矩阵变换旋转,但希望操作系统能够更有效地执行此操作,并且不想在某些其他设备上冒过度旋转的风险。
edit
Setting camera.setDisplayOrientation(90);
将预览设为纵向模式,但这对拍摄的照片没有任何影响。
此外,此外setRotation
,我也尝试过设置图片大小-我翻转的地方h
with w
: parameters.setPictureSize(1200, 1600);
。这也没有任何影响。
solution
显然,三星手机设置了 EXIF 方向标签,而不是旋转单个像素。作为ariefbayu
建议,使用读取位图BitmapFactory
不支持该标签。他的代码示例就是解决方案,并且该解决方案也兼容使用inSampleSize
.
我尝试根据 Exif 标签来回答这个问题。这就是我所做的:
Bitmap realImage = BitmapFactory.decodeStream(stream);
ExifInterface exif=new ExifInterface(getRealPathFromURI(imagePath));
Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){
realImage=ImageUtil.rotate(realImage, 90);
}else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){
realImage=ImageUtil.rotate(realImage, 270);
}else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){
realImage=ImageUtil.rotate(realImage, 180);
}
The ImageUtil.rotate()
:
public static Bitmap rotate(Bitmap bitmap, int degree) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.postRotate(degree);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)