Pick an image and resize to 72x72

后端 未结 3 655
太阳男子
太阳男子 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:25

    No, it's not that hard. Just use Bitmap.createScaledBitmap():

    Bitmap.createScaledBitmap(bitmap, width, height, true);
    
    0 讨论(0)
  • 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;
    
    }
    
    0 讨论(0)
  • 2021-01-24 15:35

    Try this-

    Bitmap yourBitmap;
    Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true);
    

    Or other way-

    resized = Bitmap.createScaledBitmap(yourBitmap,(int)(yourBitmap.getWidth()*0.8), (int)(yourBitmap.getHeight()*0.8), true);
    
    0 讨论(0)
提交回复
热议问题