setRotation(90) 在人像模式下拍照在三星设备上不起作用 [英] setRotation(90) to take picture in portrait mode does not work on samsung devices

查看:39
本文介绍了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) 在人像模式下拍照在三星设备上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆