setRotation(90)拍摄照片在纵向模式下不会对三星的设备工作 [英] setRotation(90) to take picture in portrait mode does not work on samsung devices

查看:675
本文介绍了setRotation(90)拍摄照片在纵向模式下不会对三星的设备工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据该文件,<一个href="http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setRotation%28int%29">setRotation(90)应旋转拍摄的JPEG图片(<一href="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">takePicture在横向模式下。

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

这正常工作对HTC手机,但不会对三星谷歌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); 做了preVIEW是在纵向模式,但它并没有对拍摄的图像的任何影响

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

此外,除了 setRotation ,我也试图设置图片大小 - 在我翻转 ^ h 是W 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 不支持此标记。他的code样品是解决方案,而这个方案也使用兼容 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天全站免登陆