Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create this type of brush for paint in android

Possible duplicate How to make custom brush for canvas in android?

Hello friends,

I am too stuck to create this type of brush for paint application, but didn't find anything related to this.

I am new to paint/canvas so I don't have knowledge about this for the basic I have completed but for the effect like creating brush I didn't have anything like how to create/implement it. Does anybody have example of or code for this?

I need this type of brush for my application simple one example need for understanding:

enter image description here

Thank you.

like image 460
Pratik Avatar asked Jan 19 '12 10:01

Pratik


1 Answers

I guess there is no easy way. I found this discussion and particularly the following post is interesting:

Professional Computer Graphics is never easy. That's why there are so few people really tackling it. To make things worse, professional techniques are rarely published. I don't know how much effort you desire to make to get it, but I will give you some light. So, if you want, you can study, develop and get it the best way. If it seem too hard for you, let it here as a curiosity.

The professional way to make calligraphic brushes nowadays is like that:

The master curve is smooth because it's drawn based on spline(s). To get the more professional result, construct two splines: one using the points you got (for example, from mouse events) lying over the spline and another using the points like the spline control points. So the curve you draw is the curve generated from the interpolation of these two splines. This way, you have a "master curve" to draw.

You should also have a "master thickness" on which a variation must be applied. This thickness variation is calculated according to the result you want. The more common kind of calligraphic brush is just like in the image you linked: the curved regions usually are thinner than the straight ones. It's the more usual type because most designers get this kind of result when drawing with a tablet, so programs emulate this behavior. This effect in particular is usually calculated using a function based on the second derivate of the master spline. The thickness variation amplitude can be a configurable value.

The thin and sharp curve tips are made in a extra calculation. Sometimes it can be a good idea smoothing even the thickness variations with splines or some kind of "ceil function".

If you made everything right, you have a thick (and of course closed) curve in your hands. Draw it using the best filling algorithm you can develop. Use anti-aliasing if you are able to.

All these techniques can be calculated in real time while the user moves the mouse. The more points you get, the more calculations you make, but it works well because most calculations you already made are still valid. Usually you just need to reconstruct a small (last) part.

One last suggestion: never make 2D smoothing using function regression methods, unless your points really represent a function (so you need to keep the "math meaning" of the points as much as possible). I can not imagine a slower way to smooth points that have no special semantics. The only exception is when you have very very sparse points and the input order doesn't matter, but it's not the case when somebody is drawing with brushes.

like image 195
Caner Avatar answered Sep 21 '22 14:09

Caner