Android how to scale an image with BitmapFactory Options

前端 未结 3 969
眼角桃花
眼角桃花 2020-12-18 18:52

I want to decode an image from the SD card with BitmapFactory.decodeFile(path, options).
I also want images that are larger than 2048x2048 pixels to be scaled down to at

3条回答
  •  心在旅途
    2020-12-18 19:22

    Start by setting inJustDecodeBounds to true in your Options, this will give you the size of the image, without loading any of the image data.
    If the image size is smaller then your max size, then just load it as usual.
    If on the other hand, it is too big, use the inSampleSize to read a smaller bitmap.

    Note: I don't think that the decoding does any filtering when using the inSampleSize, so you might lose some detail, but as your image size is so big (2048 px) I don't think this will cause any problems.

提交回复
热议问题