Android BitmapShader简洁实现马赛克/高斯模糊(毛玻璃),Kotlin(三)
发现,如果把(二)
Android BitmapShader简洁实现马赛克,Kotlin(二)-CSDN博客
中的这个函数:
Kotlin
private fun getMosaicBmp(srcBmp: Bitmap): Bitmap {
val smallBmp = getSmallBmp(srcBmp)
//空Bitmap
val dstBmp = Bitmap.createBitmap(mScaleImageW, mScaleImageH, Bitmap.Config.ARGB_8888)
val srcRectF = RectF(0f, 0f, smallBmp.width.toFloat(), smallBmp.height.toFloat())
val dstRectF = RectF(0f, 0f, mScaleImageW.toFloat(), mScaleImageH.toFloat())
val c = Canvas(dstBmp)
c.drawBitmap(smallBmp, srcRectF.toRect(), dstRectF.toRect(), null)
return dstBmp
}
生成返回的Bitmap方式改成简单的这样:
Kotlin
private fun getMosaicBmp(srcBmp: Bitmap): Bitmap {
val smallBmp = getSmallBmp(srcBmp)
/*
//空Bitmap
val dstBmp = Bitmap.createBitmap(mScaleImageW, mScaleImageH, Bitmap.Config.ARGB_8888)
val srcRectF = RectF(0f, 0f, smallBmp.width.toFloat(), smallBmp.height.toFloat())
val dstRectF = RectF(0f, 0f, mScaleImageW.toFloat(), mScaleImageH.toFloat())
val c = Canvas(dstBmp)
c.drawBitmap(smallBmp, srcRectF.toRect(), dstRectF.toRect(), null)
return dstBmp
*/
return Bitmap.createScaledBitmap(smallBmp,mScaleImageW, mScaleImageH,true)
}
此时,马赛克竟然变成毛玻璃(高斯模糊)的效果,如图: