如何解决在Android中自动旋转90度的图像捕获? [英] how to solve image capturing automatically rotating 90 degrees in android?

查看:153
本文介绍了如何解决在Android中自动旋转90度的图像捕获?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从相机捕获图像并将图像显示到imageview中.它将完美显示,但在某些设备中捕获的图像会自动旋转90度.我进行了很多搜索,但是找不到正确的解决方案.请告诉我解决方案.预先感谢.

I captured image from camera and display image into imageview. It will display perfect but the captured image rotated 90 degrees automatically in some devices. I searched a lot about it but could not get proper solution. Please tell me the solution for it. Thanks in advance.

推荐答案

使用此方法确定图像旋转.

Use this method to determine image rotation.

 public int getCameraPhotoOrientation(Uri imageUri, String imagePath) {
        int rotate = 0;
        try {
            _context.getContentResolver().notifyChange(imageUri, null);
            File imageFile = new File(imagePath);
            ExifInterface exif = new ExifInterface(
                    imageFile.getAbsolutePath());
            int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);

            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotate = 270;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotate = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotate = 90;
                    break;
            }


        } catch (Exception e) {
        }
        return rotate;
    }

如果该方法不返回零,则会旋转图像.

And if the method wouldn't return Zero rotated the image.

int degree=getCameraPhotoOrientation(Uri.fromFile(tempFile), fPath);
if (degree!= 0) {
      bitmap = tools.rotateOrientationCall(bitmap, degree);
 }

旋转您的位图.

 public Bitmap rotateOrientationCall(Bitmap src, float degree) {
        Matrix matrix = new Matrix();
        matrix.postRotate(degree);
        return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    }

这篇关于如何解决在Android中自动旋转90度的图像捕获?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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