简体   繁体   中英

Open Image from Gallery Only in Portrait mode

I'm building an app which will open an image from gallery. The image is opened successfully but I would like to know if I can force the image to be opened in portrait mode?

This is the Intent I'm using:

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

if you having an issue with the image rotation well i advice you to use this method as its the simplest and most efficient way.

            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);

hope this is what you are looking for :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM