首頁 >web前端 >js教程 >Canvas and Drawables 翻譯第二集

Canvas and Drawables 翻譯第二集

黄舟
黄舟原創
2017-01-16 16:42:411140瀏覽


Android官方原文地址:http://developer.android.com/guide/topics/graphics/2d-graphics.html

------以下的翻譯融入了自己的思考,便於理解,很多地方翻譯並不是很恰當,所以配上了英文原文


Draw with a Canvas 用畫板(Canvas)繪製

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

Canvas

.
A Canvas works for you as a pretense, or interface, to the actual surface upon which your graphics will be drawnface — it s surface upon which your graphics . Via the Canvas, your drawing is actually performed upon an underlying

Bitmap
,
which is placed into the window.

當你寫一個應用的時候,在應用裡你想要執行特別的圖形(Graphics)動畫,你應該透過畫板(Canvas)來繪製。一個畫板作為一個介面為你工作,實際上是一個介面,你的圖形將要繪製在上面---它(Canvas)擁有所有的繪製方法。透過畫板(Canvas),你的繪製實際上執行在一個潛在的點陣圖紙上(Bitmap),點陣圖紙被放在視窗裡(window)。

In the event that you're drawing within the

onDraw()

callback
method, the Canvas is provided for you and

callback

method, the Canvas is provided for you and callback
method, the Canvas is provided for you and
callback

method orcavas is provided for you and

on place placehall ​​recauscanh youfreca 您

SurfaceHolder.lockCanvas()
,
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 drawing will actually be performed. The Bitmap is always required for a Canvas. You can set up a new Canvas like this:

如果你正在onDraw()回調方法裡繪製,畫板(Canvas)已經提供給你,而你只提供給你,而你隻隻提供需要用它的繪製方法在它上面繪製。當你要用SurfaceVeiw物件處理的時候,你也能從Surface.lockCanvas()裡獲得Canvas。以上兩種情況在下面已被討論。不管怎樣,如果你需要建立一個新的Canvas,你必須定義一個Bitmap,繪製實際上是執行在Bitmap上的。這個Bitmap對於Canvas是必須的。你能夠設定一個新的Canvas,像這樣:

Bitmap

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, you can then carry your Bithimap to another Canvas with one of the Canvas, you can then carry your Bitemap to another Canvas with one of the Canvas, you can then carry your Bitrel.

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

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

or

Canvas.drawBitmap(Bitmap,...)

(see

the following sections).


現在你的Canvas將要繪製圖形到這個已經定義的Bitmap上。在Bitmap上繪製之後,你能夠透過

View.onDraw()

把你的Bitmap搬到另一個Canvas裡面。推薦你使用透過View.onDraw()方法或SurfaceHolder.lockCanvas()提供給你的Canvas繪製你最終的圖形。

The

SurfaceHolder.lockCanvas()

class has its own set

of drawing methods that you can use, like

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

,

Canvas

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

draw()

methods. For example, you'll probably have some

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

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

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


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn