Examples of various graphics rendering functions developed and implemented by Android

This paper describes the development of Android to achieve various graphics rendering functions. Share with you for your reference, as follows:

Here, combined with my development example, I briefly introduce how to draw various graphics on Android platform.

First, customize a view class. In this view class, you need a paint object to control the attributes of graphics, a path object to record the path of graphics drawing, a canvas class to perform drawing operations, and a bitmap class to hold the drawing results.

The above code initializes the paint object and sets the color, type and thickness of the brush.

The above code creates a bitmap object, passes it as a parameter to the canvas object, and initializes the path object.

To make the view respond to the user's touch event, you need to implement the ontouchevent function of the view class. The code is as follows:

Where touch_ start,touch_ Move and touch_ The up function handles press, move and lift events respectively. The implementation of the function will be introduced later. The invalidate function will call the OnDraw function to ensure that the drawing effect is displayed in real time.

touch_ The start function is implemented as follows

Each time you empty the path, move to the starting point and record the starting point.

touch_ The move function is implemented as follows:

Draw different graphics according to the value of mshape. When it is 1, draw Bezier curve, when it is 2, draw straight line, when it is 3, draw ellipse, and when it is 4, draw rectangle. Call different functions of path class respectively.

touch_ The up function is implemented as follows:

Draw path into canvas bitmap

Finally, the current bitmap needs to be drawn in the OnDraw function.

It's done. The screenshot is as follows:

More readers interested in Android related content can view the special topics of this site: summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills, and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>