Android studio decodeStream以横向方向返回图像

Android studio decodeStream以横向方向返回图像,android,android-studio,bitmap,stream,orientation,Android,Android Studio,Bitmap,Stream,Orientation,在android studio项目中,我使用BitmapFactory.decodeStream方法从图库中获取图像。但是接收到的位图始终是横向的,因此高度大于宽度的图片会旋转90度。如何解决这个问题?下面是getter代码 public static Bitmap decodeSampledBitmapFromResource(Context context, Uri resourceUri, int reqWidth, int reqHeight) throws IOException {

在android studio项目中,我使用
BitmapFactory.decodeStream
方法从图库中获取图像。但是接收到的位图始终是横向的,因此高度大于宽度的图片会旋转90度。如何解决这个问题?下面是getter代码

public static Bitmap decodeSampledBitmapFromResource(Context context, Uri resourceUri, int reqWidth, int reqHeight) throws IOException {
    InputStream imageStream = context.getContentResolver().openInputStream(resourceUri);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(imageStream, null, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    imageStream.close();
    imageStream = context.getContentResolver().openInputStream(resourceUri);
    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;

    //the bitmap is always in landscape orientation
    return BitmapFactory.decodeStream(imageStream, null, options);
}

private static int calculateInSampleSize(
    BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of the image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {
        final int halfHeight = height / 2;
        final int halfWidth = width / 2;

        // Calculate the largest inSampleSize value that is a power of 2 and keeps both
        // height and width larger than the requested height and width.
        while ((halfHeight / inSampleSize) >= reqHeight
                    && (halfWidth / inSampleSize) >= reqWidth) {
            inSampleSize += 1;
        }
    }

    return inSampleSize;
}