Android的正面和背面的摄像头拍摄的照片方向问题,以错误的方式旋转 [英] android front and back camera captured picture orientation issue, rotated in a wrong way

查看:195
本文介绍了Android的正面和背面的摄像头拍摄的照片方向问题,以错误的方式旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在纵向模式下相机应用程序,它来自前端和后端cameras.The问题拍摄照片像拍摄的图像以错误的方式旋转......

I have a camera app in portrait mode which takes pictures from both front and back end cameras.The issue is like the captured images are rotated in a wrong way...

有关preVIEW我用下面的code ....

For preview i have used the following code....

    Camera.Parameters parameters = camera.getParameters();
        android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
        android.hardware.Camera.getCameraInfo(defaultCameraId, info);
        int rotation = this.getWindowManager().getDefaultDisplay()
                .getRotation();
        if (Integer.parseInt(Build.VERSION.SDK) >= 8) {

            int degrees = 0;
            switch (rotation) {
            case Surface.ROTATION_0:
                degrees = 0;
                break;
            case Surface.ROTATION_90:
                degrees = 90;
                break;
            case Surface.ROTATION_180:
                degrees = 180;
                break;
            case Surface.ROTATION_270:
                degrees = 270;
                break;
            }
            int result;
            if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                result = (info.orientation + degrees) % 360;
                result = (360 - result) % 360; // compensate the mirror
            } else { // back-facing
                result = (info.orientation - degrees + 360) % 360;
            }

            camera.setDisplayOrientation(result);

        } else {
            parameters.set("orientation", "portrait");
        }

        camera.setParameters(parameters);

不过,拍摄的图像在一个错误的way.i旋转也试图用旋转拍摄的图像 matrix.postRotate(位图)。那太不工作像nexus..I一些设备试图EXIF also.But在这里我有网址,而不是filepath.That不能正常工作。谁能帮助我?

But the captured images are rotated in a wrong way.i have also tried to rotate the captured image using matrix.postRotate(bitmap).That too doesn't work in some devices like nexus..I tried EXIF also.But here i have url instead of filepath.That doesn't work as well. can anyone help me ?

推荐答案

您可以参考以下code。

You can refer below code.

ExifInterface exif = new ExifInterface(SourceFileName);     //Since API Level 5

String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);

和同时参考这个链接 http://stackoverflow.com/a/6124375/1441666

这篇关于Android的正面和背面的摄像头拍摄的照片方向问题,以错误的方式旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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