Android Gallery应用程序,如果选定的照片宽度大到高度,则照片看起来是垂直的

Android Gallery应用程序,如果选定的照片宽度大到高度,则照片看起来是垂直的,android,Android,我尝试了一个画廊应用程序。 我的应用程序工作2个不同的形式。 从“多媒体资料”或“相机选择”中, 如果选择的照片高度大到宽度,一切正常。 如果选定的照片宽度大于高度,则照片看起来是垂直的 例如, 此图像宽度:3264,高度:2448 我的应用程序看起来像这样 这是我的解码码,对不起英语不好,谢谢 private class DecodeSize extends AsyncTask<String,Void,Bitmap> { private int reqWidt

我尝试了一个画廊应用程序。 我的应用程序工作2个不同的形式。 从“多媒体资料”或“相机选择”中, 如果选择的照片高度大到宽度,一切正常。 如果选定的照片宽度大于高度,则照片看起来是垂直的

例如, 此图像宽度:3264,高度:2448

我的应用程序看起来像这样

这是我的解码码,对不起英语不好,谢谢

private class DecodeSize extends AsyncTask<String,Void,Bitmap> {

        private int reqWidth;
        private int reqHeight;
        private ImageView imageView;
        private final WeakReference<ImageView> imageViewReference;

        private DecodeSize(int reqWidth, int reqHeight, ImageView imageView) {
            this.reqWidth = reqWidth;
            this.reqHeight = reqHeight;
            this.imageViewReference = new WeakReference<ImageView>(imageView);
        }


        public int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) {
            // Raw height and width of 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 *= 2;
                }
            }

            return inSampleSize;
        }

        @Override
        protected Bitmap doInBackground(String... params) {
            String photo_path = params[0];

            // First decode with inJustDecodeBounds=true to check dimensions
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(photo_path, options);

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

            // Decode bitmap with inSampleSize set
            options.inJustDecodeBounds = false;
            return BitmapFactory.decodeFile(photo_path, options);
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            if(imageViewReference != null && bitmap !=null) {
                final ImageView imageView = imageViewReference.get();
                if (imageView != null) {
                    imageView.setImageBitmap(bitmap);
                }
            }
        }
    }

    private void decodeSizeFunction(String picturePath) {
        decodeSize = new DecodeSize(200,200,foto_image);
        decodeSize.execute(picturePath);
    }
私有类DecodeSize扩展异步任务{
私家车的宽度;
私家车高度;
私人影像视图;
私有最终WeakReference imageViewReference;
专用解码大小(int-reqWidth、int-reqHeight、ImageView-ImageView){
此参数为0.reqWidth=reqWidth;
此参数。reqHeight=reqHeight;
this.imageViewReference=新的WeakReference(imageView);
}
公共int-calculateInSampleSize(BitmapFactory.Options选项、int-reqWidth、int-reqHeight){
//图像的原始高度和宽度
最终内部高度=options.outHeight;
最终整数宽度=options.outWidth;
int inSampleSize=1;
如果(高度>要求高度| |宽度>要求宽度){
最终int半高=高度/2;
最终整数半宽度=宽度/2;
//计算最大的inSampleSize值,该值为2的幂次方,并同时保持这两个值
//高度和宽度大于请求的高度和宽度。
而((半高/采样)大于所需高度
&&(半宽/采样尺寸)>reqWidth){
inSampleSize*=2;
}
}
返回样本大小;
}
@凌驾
受保护位图doInBackground(字符串…参数){
字符串photo_path=params[0];
//使用INJUSTDECBOUNDS首次解码=true检查尺寸
final BitmapFactory.Options=new BitmapFactory.Options();
options.inJustDecodeBounds=true;
解码文件(照片路径,选项);
//计算样本大小
options.inSampleSize=计算样本大小(options、reqWidth、reqHeight);
//使用inSampleSize集合解码位图
options.inJustDecodeBounds=false;
返回BitmapFactory.decodeFile(照片路径,选项);
}
@凌驾
受保护的void onPostExecute(位图){
if(imageViewReference!=null&&bitmap!=null){
最终ImageView=imageViewReference.get();
如果(imageView!=null){
设置图像位图(位图);
}
}
}
}
私有void decodesize函数(字符串picturePath){
decodeSize=新的decodeSize(200200,foto_图像);
decodeSize.execute(picturePath);
}

使用android query调整图像大小和缩放。我尝试了毕加索库,但出现了其他问题