Pick an image and resize to 72x72

后端 未结 3 656
太阳男子
太阳男子 2021-01-24 14:54

I picked an image from gallery and decoded it. Now I just want to resize that bitmap to standard 72x72 size in order to use as an profile photo.

I searched a lot but not

3条回答
  •  孤街浪徒
    2021-01-24 15:30

    This is an example of a method that would give me a maximum of 120x120 image, hope this helps you :

    public static Bitmap decodeWithBounds(String srcImg) {
    
        Bitmap image;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(srcImg, options);
    
    
        if (options.outHeight > 120 || options.outWidth > 120) {
    
            options.inSampleSize = Math.max(
                    Math.round(options.outHeight / 120),
                    Math.round(options.outWidth / 120));
        }
        options.inJustDecodeBounds = false;
        image = BitmapFactory.decodeFile(srcImg, options);
        return image;
    
    }
    

提交回复
热议问题