Home > Web Front-end > JS Tutorial > Canvas and Drawables Translation Episode 2

Canvas and Drawables Translation Episode 2

黄舟
Release: 2017-01-16 16:42:41
Original
1129 people have browsed it


Android official original address: http://developer.android.com/guide/topics/graphics/2d-graphics.html

------The following translation has been incorporated into itself Thinking, easy to understand, the translation in many places is not very appropriate, so the original English text


Draw with a Canvas Draw with a drawing board (Canvas)

When you 're writing an application in which you would like to perform specialized drawing and/or control the animation of graphics, you should do so by drawing through a

Canvas
Copy after login

.
A Canvas works for you as a pretense, or interface, to the actual surface upon which your graphics will be drawn — it holds all of your "draw" calls. Via the Canvas, your drawing is actually performed upon an underlying

Bitmap
Copy after login
Copy after login
,
which is placed into the window.

When you write an application, and you want to perform special graphics drawing or control animation in the application, you should draw it through the Canvas. An artboard works for you as an interface. It is actually the interface on which your graphics will be drawn - it (Canvas) has all the drawing methods. With the Canvas, your drawing is actually performed on an underlying bitmap drawing (Bitmap), which is placed in the window (window).

In the event that you're drawing within the

onDraw()
Copy after login

callback
method, the Canvas is provided for you and you need only place your drawing calls upon it. You can also acquire a Canvas from

SurfaceHolder.lockCanvas()
Copy after login
Copy after login

,
when dealing with a SurfaceView object. (Both of these scenarios are discussed in the following sections.) However, if you need to create a new Canvas, then you must define the

Bitmap
Copy after login
Copy after login

upon
which drawing will actually be performed. The Bitmap is always required for a Canvas. You can set up a new Canvas like this:

If you are drawing in the onDraw() callback method, the artboard (Canvas) is already provided to you, and you only need to use its The draw method draws on it. When you want to deal with the SurfaceVeiw object, you can also get the Canvas from Surface.lockCanvas(). The above two situations are discussed below. Regardless, if you need to create a new Canvas, you must define a Bitmap, and drawing is actually performed on the Bitmap. This Bitmap is necessary for Canvas. You can set up a new Canvas, like this:

Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
Copy after login

Now your Canvas will draw onto the defined Bitmap. After drawing upon it with the Canvas, you can then carry your Bitmap to another Canvas with one of the

Canvas.drawBitmap(Bitmap,...)
Copy after login

methods.
It's recommended that you ultimately draw your final graphics through a Canvas offered to you by

View.onDraw()
Copy after login

or

SurfaceHolder.lockCanvas()
Copy after login
Copy after login

(see
the following sections ).

Now your Canvas will draw graphics to this defined Bitmap. After drawing on the Bitmap, you can move your Bitmap to another Canvas through

Canvas.drawBitmap(Bitmap,...)方法其中的一种
Copy after login

. It is recommended that you use the Canvas provided to you through the View.onDraw() method or SurfaceHolder.lockCanvas() to draw your final graphics.

The

Canvas
Copy after login

class has its own set
of drawing methods that you can use, like

drawBitmap(...)
Copy after login

,

drawRect(...)
Copy after login
,
drawText(...)
Copy after login

,

and many more. Other classes that you might use also have

draw()
Copy after login
Copy after login

methods. For example, you'll probably have some

Drawable
Copy after login
objects
that you want to put on the Canvas. Drawable has its own
draw()
Copy after login
Copy after login
method
that takes your Canvas as an argument.

这个Canvas类有它自己的一系列绘制方法,并且你可以使用,像drawBitmap(...),drawRect(),drawText()等等。你可能用到的其他含有draw()方法的类,例如:你有一些Drawable对象,并且你想绘制到Canvas上。Drawable有它自己的draw()方法,它把Canvas作为参数传进去,将自己绘制到Canvas上。

以上就是Canvas and Drawables 翻译第二集的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template