【问题标题】:Open Image from Gallery Only in Portrait mode仅在纵向模式下从图库中打开图像
【发布时间】:2018-11-30 13:55:42
【问题描述】:

我正在构建一个可以从图库中打开图片的应用。图片已成功打开,但我想知道是否可以强制以纵向模式打开图片?

这是我正在使用的意图:

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file),"image/*");
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);

【问题讨论】:

    标签: android image


    【解决方案1】:

    如果您在图像旋转方面遇到问题,我建议您使用这种方法,因为它是最简单和最有效的方法。

                String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION };
            @SuppressWarnings("deprecation")
            Cursor cur = managedQuery(imageFileUri, orientationColumn, null,
                    null, null);
            int orientation = -1;
            if (cur != null && cur.moveToFirst()) {
                orientation = cur.getInt(cur
                        .getColumnIndex(orientationColumn[0]));
            }
            Matrix matrix = new Matrix();
            matrix.postRotate(orientation);
            bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
                    bmp.getHeight(), matrix, true);
            view.setImageBitmap(bmp);
    

    希望这就是你要找的:)

    【讨论】:

      【解决方案2】:

      在每个<activity/> 标签的清单中使用android:screenOrientation="portrait"...它会起作用...我的朋友..试试看

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-10
        • 1970-01-01
        • 1970-01-01
        • 2014-03-26
        • 2011-09-05
        • 2020-08-03
        • 2013-11-21
        • 2016-12-13
        相关资源
        最近更新 更多