Recently, a project designed an app to achieve a brush and write effect through a touch screen. The traditional drawing board program directly through the path of the MoveTo and LineTo can achieve a simple line painting program. However, in order to achieve the brush strokes the effect needs a more detailed design. My implementation of the idea is to touch the event down, MOVE, the top of each point to draw a circle, in addition to the size of the touch pressure to change the radius of the painted circle, so that a series of circles can be roughly simulated brush pen flick effect, in the design of the sub-effect encountered two problems:
1:android touch in the move time to pick the point frequency is not very high, will be separated by a certain pixel points, when the touch sliding will appear a day discontinuous circle, obviously does not conform to the flick effect. Then my solution is to drrawline between adjacent circles, the size of the brush is similar to the diameter of the circle, so that a discrete circle is connected together to form a continuous flick effect.
2. A similar procedure for WordPad is to draw more than one curve on the canvas. My implementation is to save the points in the screen to the list (list<list<object>>) in the Ontouch event that inherits from the view class. Each added point is invalidate with a re-painting cloth (onDraw). When the OnDraw function draws a line, it iterates through the list, each point draws a circle, and the circle is connected through lines. Test found that when too many lines when the program will appear in the phenomenon, self-study review drawing This process will be found to be ondraw in the frequent drawing affects the efficiency of the program. In this case, through the picture caching technology is a good solution to this problem, the concrete realization of the idea is as follows: To create a buffer canvas, and buffer Bitmap,ontouch event to draw the circle and line into the buffer bitmap. Draw the buffered bitmap directly into the canvas (Canvas.drawbitmap (Bitmap.paint)) in the OnDraw function.
Of course, so the design of the pen effect is very rough, but also through the beginning of each stroke, turning point and end point design different shapes to enrich the effect of brush flicks
Achieve a brush effect in Android (View in the drawing)