How to Resize a Bitmap in Android?

后端 未结 16 2040
有刺的猬
有刺的猬 2020-11-22 03:13

I have a bitmap taken of a Base64 String from my remote database, (encodedImage is the string representing the image with Base64):

profileImage          


        
16条回答
  •  无人及你
    2020-11-22 03:45

    /**
     * Kotlin method for Bitmap scaling
     * @param bitmap the bitmap to be scaled
     * @param pixel  the target pixel size
     * @param width  the width
     * @param height the height
     * @param max    the max(height, width)
     * @return the scaled bitmap
     */
    fun scaleBitmap(bitmap:Bitmap, pixel:Float, width:Int, height:Int, max:Int):Bitmap {
        val scale = px / max
        val h = Math.round(scale * height)
        val w = Math.round(scale * width)
        return Bitmap.createScaledBitmap(bitmap, w, h, true)
      }
    

提交回复
热议问题