setRotation(90) 在人像模式下拍照在三星设备上不起作用

编程入门 行业动态 更新时间:2024-10-12 08:21:06
本文介绍了setRotation(90) 在人像模式下拍照在三星设备上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

根据文档,setRotation(90) 应该旋转捕获的 JPEG 图片(takePicture 横向模式.

According to the documentation, setRotation(90) should rotate the captured JPEG picture (takePicture in landscape mode.

这适用于 HTC 手机,但不适用于三星 Google Nexus S 和三星 Galaxy S3.这是一个错误吗?

This works fine on a HTC phone, but does not work on Samsung Google Nexus S and Samsung Galaxy S3. Is this a bug?

我知道我可以使用矩阵变换旋转,但希望操作系统可以更有效地执行此操作,并且不想在其他设备上冒过度旋转的风险.

I know that I can use the matrix transform rotation, but wish the OS can do this more efficiently, and don't want to risk over-rotating on some other devices.

编辑

设置camera.setDisplayOrientation(90);使预览为纵向模式,但对拍摄的照片没有任何影响.

Setting camera.setDisplayOrientation(90); made the preview to be in portrait mode, however it did not have any affect on the picture taken.

此外,除了 setRotation,我还尝试设置图片大小 - 我用 w 翻转 h 的地方:parameters.setPictureSize(1200, 1600);.这也没有任何影响.

Further, Besides setRotation, I have also tried to set the picture size - where I flip h with w: parameters.setPictureSize(1200, 1600);. This also did not have any affect.

解决方案

显然,三星手机设置了 EXIF 方向标签,而不是旋转单个像素.正如 ariefbayu 所建议的,使用 BitmapFactory 读取位图不支持此标签.他的代码示例就是解决方案,这个解决方案也兼容使用inSampleSize.

Apparently Samsung phones set the EXIF orientation tag, rather than rotating individual pixels. As ariefbayu suggested, reading the Bitmap using BitmapFactory does not support this tag. His code sample is the solution, and this solution is also compatible with using inSampleSize.

推荐答案

我尝试通过 Exif 标签来回答这个问题.这就是我所做的:

I try to answer this in relation to the Exif tag. This is what I did:

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); }

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); }

更多推荐

setRotation(90) 在人像模式下拍照在三星设备上不起作用

本文发布于:2023-11-27 13:25:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638258.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:人像   上不   设备   模式下   setRotation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!