Resizing a bitmap to a fixed value but without changing the aspect ratio

后端 未结 5 1614
清歌不尽
清歌不尽 2021-02-02 16:41

I\'m looking for a solution for the following problem: how to change the size of a Bitmapto a fixed size (for example 512x128). The aspect ratio of the bitmap conte

5条回答
  •  忘了有多久
    2021-02-02 17:17

    https://developer.android.com/reference/android/graphics/Bitmap.html#createScaledBitmap(android.graphics.Bitmap, int, int, boolean)

    and make sure that both the dstWidth and dstHeight are obtained from src.getWidth()*scale and src.getHeight()*scale, where scale is a value that you need to determine to make sure the scaled bitmap fits inside 512x128.

提交回复
热议问题