Android: draw “irregular” strokes on the canvas, a kind of chalk on the blackboard

I want to achieve an effect like this:

chalk on blackboard effect

Does anyone have an idea on how to draw such a line on canvas?

+4
source share
2 answers

a little closer:

chalkPaint = new Paint(); chalkPaint.setStyle(Style.STROKE); chalkPaint.setStrokeWidth(12); Bitmap chalkShader = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.chalk_texture)).getBitmap(); chalkPaint.setShader(new BitmapShader(chalkShader, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT)); 

this draws a texture with chalk:

chalk texture

now I just need an irregular border ... still trying ...

+1
source

This is probably harder than you think.

Drawing such a line is mainly based on randomness. For example, between "M" and "N" in your picture, I think that there is not one, but four consecutive small lines of different sizes of the brush (randomly selected in a small interval). Take a closer look and you will see them.

The coordinates of these four small lines are also arbitrarily adjusted (to a very small extent) to avoid the straight line that was once collected.

There may also be a random number of small lines between two squares (I think there are more than four small lines between "R" and "X").

You can try to find a library that already does the job, I don’t know if it is, but it is not possible.

0
source

All Articles