Introduction to skia engine APIs (skia in Android 2.3 trunk)

Source: Internet
Author: User
Tags skia

Http://blog.csdn.net/wxzking/article/details/6419219

Collation
Through Google, Baidu, We are hard to find documentation on the skia engine, skia's official Wiki (http://code.google.com/p/skia) also has only a few words to briefly introduce skcanvas, I analyzed the source code and checked the JNI interface's encapsulation of the skia engine. I summarized and translated some of the following texts, if you want to draw native images on the Android platform, you can also use OpenGL to draw images.

Position of the skia engine in the android source code library

Header file (or internal API, because Google does not provide it in ndk) Location: Android/external/skia/include. It also contains the following subdirectories: animator, core, effects, images, views ..., the most important thing is the core directory. Our analysis here is mainly for the APIs in the core directory.

The source file is located in the directory Android/external/skia/src. The subdirectory structure is the same as the header file directory.
Encapsulation layer: Android encapsulates the skia engine so that Java code can be conveniently called, the codes encapsulated for skia exist in the android/framework/base/CORE/JNI and Android/framework/base/CORE/JNI/Android/graphics directories. It is mainly used to encapsulate canvas, bitmap, graphics, picture, and so on, as well as to combine with the libui library.

Introduction to important skia Engines
(PS: note that it is an introduction. The audience should not be too demanding. I am also working on the documents)
1. skcanvas
This class is a core class of the skia engine, which encapsulates all painting operations on the device. This class itself contains a reference to a device, as well as a matrix and a cropping stack. All painting operations are performed after the matrix of stack memory changes (similar to OpenGL ). Of course, the image that is finally displayed to the user must also undergo the operation of cropping the stack.
Skcanvas records the painting status of the entire device, and the status of the objects drawn on the device is recorded by the skpaint class. The skpaint class is used as a parameter, the member function drawxxxx () passed to different skcanvas classes (). (For example, drawpoints, drawline, drawrect, drawcircle ). The skpaint Class records such as color, typeface, textsize, strokewidth, and gradients.
Main member functions of the skcanvas class:
> Constructor: If a bitmap or device is specified, the device can be empty for drawing on the given object.
Skcanvas (const skbitmap & Bitmap );
Skcanvas (skdevice * Device = NULL );
> Setviewport and getviewport are valid only when OpenGL views are supported.
> Save, savelayer, savelayeralpha, and restore functions are used to save and restore the display matrix, cut, and filter stacks. Different functions have different additional functions.
> Shift, zoom, rotate, and deform functions.
Translate (skiascalar dx, skiascalar Dy );
Scale (skscalar Sx, skscalar Sy );
Rotate (skscalar degrees );
Skew (skscalar Sx, skscalar Sy );
> Specify a specific matrix and perform corresponding transformation functions. The preceding four methods can be implemented by defining a specific matrix and then calling this function.
Cancat (const skmatrix & matrix );
> Image editing: displays the specified area.
Cliprect (skrect &...);
Clippath (skpath &...);
Clipregion (skregion &...);
> You can draw images on the current canvas in the following ways:
Drawargb (u8 A, u8 R, u8 g, u8 B...) for transparency and red, green, blue 3 colors, fill the entire area of the painting.
Drawcolor (skcolor color...) specifies the color and fills the entire painting area.
Drawpaint (skpaint & paint) fills the entire area with the specified paint brush.
Drawpoint (...)/drawpoints (...) draw different points based on different parameters.
Drawline (x0, y0, X1, Y1, paint) Draw line, start point (x0, y0), End Point (x1, Y1), use paint as the paint brush.
Drawrect (rect, paint) draws a rectangle. The size of the rectangle is specified by rect, And the paint brush is specified by painting.
Drawrectcoords (left, top, right, bottom, paint). Four border painting matrices are given.
Drawoval (skrect & oval, skpaint & paint) draws an elliptical shape. The Oval size is specified by the Oval rectangle.
Drawcicle (CX, Cy, radius, paint), which is used to draw a circle with the coordinates and radius of the center.
Drawarcskrect & oval...) draws an arc, which is similar to an elliptic.
Drawroundrect (rect, RX, Ry, paint) draws a rounded rectangle, radians in the X and Y directions are specified with RX and ry.
Draw the drawpath (path, paint) path based on the path specified by the path.
Drawbitmap (skbitmap & bitmap, left, top, paint = NULL) draws the specified bitmap. The paint can be empty.
Drawbitmaprect (bitmap, SRC, DEST, paint = NULL): draws a part of the given bitmap, which is specified by Src, and then draws the part of the captured bitmap to the area specified by DeST, possible scaling.
Drawbitmapmatrix (bitmap, matrix, paint = NULL) has the same effect as above. You can crop and scale a matrix.
Drawsprite (bitmap, left, top, paint = NULL), draws a bitmap, not affected by the current transformation matrix.
Drawtext (void * Text, bytelength, X, Y, paint), writes text starting from (x, y). The text is stored in the text pointer and the length is specified by bytelength.
The drawpostext (...) function is the same as above, but each text can be specified separately.
The drawpostexth (...) function is the same as above. However, a variable specifies the uniform Y coordinates of all current texts, that is, to write at different intervals on the same horizontal line.
Drawtextonpathhv, drawtextonpath, and drawtextonpath draw text on the specified path in different ways.
Drawpicture (skpicture & picture) draws images on the canvas, a more efficient drawing function.
Drawshape (skshape *) draws an image of the specified shape on the canvas.
Drawvertices (...) can be used to draw points, including textures, colors, and other additional options.
Author: Aries @ miou
Address: http://www.meegozu.com
You are welcome to repost. Please keep the above information when reprinting.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.