I have two views: View1 and View2. View1 draws a point with BlurMaskFilter
on a canvas with a scale amount 3F
. View2 first draws that point on a bitmap at 1x scale, and then the bitmap is drawn on the canvas, with 3x scale.
Now I expect the two views to draw the visually identical images, but it doesn't. Anyone can tell why it's like this?
View1:
class DemoView1 : View {
constructor(context: Context?) : this(context, null)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
private var paint: Paint = Paint()
init {
paint.apply {
strokeWidth = 500F
style = Paint.Style.FILL
color = Color.RED
strokeJoin = Paint.Join.ROUND
strokeCap = Paint.Cap.ROUND
maskFilter = BlurMaskFilter(200F, BlurMaskFilter.Blur.NORMAL)
}
}
override fun onDraw(canvas: Canvas) {
canvas.scale(3F, 3F)
canvas.drawPoint(0F, 0F, paint)
}
}
View2:
class DemoView2 : View {
constructor(context: Context?) : this(context, null)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
private var paint: Paint = Paint()
init {
paint.apply {
strokeWidth = 500F
style = Paint.Style.FILL
color = Color.RED
strokeJoin = Paint.Join.ROUND
strokeCap = Paint.Cap.ROUND
maskFilter = BlurMaskFilter(200F, BlurMaskFilter.Blur.NORMAL)
}
}
@SuppressLint("DrawAllocation")
override fun onDraw(canvas: Canvas) {
val bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888)
val bitmapCanvas = Canvas(bitmap)
bitmapCanvas.apply {
drawPoint(0F, 0F, paint)
}
canvas.scale(3F, 3F)
canvas.drawBitmap(bitmap, 0F, 0F, Paint())
}
}
The upper one is View1, and lower one is View2.