在 Canvas Bitmap Android 中调整大小时图像像素化

问题描述

enter image description here

logo i.e Circle 是 png 图像,其质量下降,如图所示。 在发布这个问题之前,我参考了 Stackoverflow 中所有可能的解决方案,但没有一个我有用。

要根据我的使用情况调整图片大小,我目前正在使用下面的方法

fun BITMAP_RESIZER(bitmap: Bitmap,newWidth: Int,newHeight: Int): Bitmap? {
    val scaledBitmap = Bitmap.createBitmap(newWidth,newHeight,Bitmap.Config.ARGB_8888)
    val ratioX = newWidth / bitmap.width.toFloat()
    val ratioY = newHeight / bitmap.height.toFloat()
    val middleX = newWidth / 2.0f
    val middleY = newHeight / 2.0f
    val scaleMatrix = Matrix()
    scaleMatrix.setScale(ratioX,ratioY,middleX,middleY)
    val canvas = Canvas(scaledBitmap)
    canvas.setMatrix(scaleMatrix)
    canvas.drawBitmap(
        bitmap,middleX - bitmap.width / 2,middleY - bitmap.height / 2,Paint(Paint.FILTER_BITMAP_FLAG)
    )
    return scaledBitmap
}

结果,你可以看到它的质量仍然没有提高。除了这个解决方案,我已经使用了所有其他方法,但没有一个适合我。

你能告诉我我做错了什么或任何其他可能的答案吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)