以纵向模式拍照的setRotation(90)对三星设备不起作用

tof*_*fi9 36 android android-camera

根据该文件,setRotation(90)应旋转拍摄的JPEG图片(takePicture在横向模式.

这在HTC手机上运行良好,但在三星Google Nexus S和三星Galaxy S3上无效.这是一个错误吗?

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

编辑

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

此外,另外setRotation,我也试图设置图片大小-在我翻转hw:parameters.setPictureSize(1200, 1600);.这也没有任何影响.

显然,三星手机设置了EXIF方向标签,而不是旋转单个像素.如ariefbayu建议的那样,使用Bitmap BitmapFactory不支持此标记.他的代码示例是解决方案,此解决方案也与使用兼容inSampleSize.

ari*_*ayu 34

我尝试回答与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);
}
Run Code Online (Sandbox Code Playgroud)

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);
}
Run Code Online (Sandbox Code Playgroud)