关于 ImageView 方向

Regarding ImageView Orientation

我使用 intent 将图像捕获到 imageview 中,但在设置时它旋转了 90 或 270 。如何限制这个轮换?

Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                           i.putExtra(MediaStore.EXTRA_OUTPUT,Uri.parse("file:///"+mProfile_Image));
startActivityForResult(i, 1);                                       

// Set to imageview

mProfileImage.setImageURI(Uri.parse("file:///"+mProfile_Image));


// here imageview is the path

您不需要限制旋转。

尝试以下方法

Uri imageUri = Uri.parse(path);
        String imagePath = path;

        int rotate = 0;
// initializing
    int dpWidth = 100;
    int dpHeight = 100;
        try {
            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) {
            e.printStackTrace();
        }

        dpWidth = (int) ((outMetrics.widthPixels / density) * .75);

        dpHeight = (int) ((outMetrics.heightPixels / density) * .75);

        Matrix matrix = new Matrix();
        matrix.postRotate(rotate);

这将帮助您显示正确的图像

编辑

此代码不用于永久旋转图像。所以每当你想在 inmageView 中显示图像时,只需旋转并添加。

编辑 1

使用它在 imageview 中设置图像

Bitmap bm = BitmapFactory.decodeFile(path);
Bitmap bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(),
                    matrix, true);
imageView.setImageBitmap(bm);

将 activity 的方向设置为纵向并试一试。

<activity 
        android:name="YourActivityName"
        android:screenOrientation="portrait">
</activity>