最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

CanvasandDrawables翻译第二集

来源:动视网 责编:小采 时间:2020-11-27 20:26:29
文档

CanvasandDrawables翻译第二集

CanvasandDrawables翻译第二集:Android官方原文地址:http://developer.android.com/guide/topics/graphics/2d-graphics.html------以下的翻译融入了自己的思考,便于理解,很多地方翻译并不是很恰当,所以配上了英文原文Draw with a Canvas 用画板(Canvas)绘制
推荐度:
导读CanvasandDrawables翻译第二集:Android官方原文地址:http://developer.android.com/guide/topics/graphics/2d-graphics.html------以下的翻译融入了自己的思考,便于理解,很多地方翻译并不是很恰当,所以配上了英文原文Draw with a Canvas 用画板(Canvas)绘制



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 control the animation 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 drawn — it holds all of your "draw" calls. 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 you need only place your drawing calls upon it. You can also acquire a Canvas from

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

Bitmap

upon
which 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 b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);

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,...)

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

View.onDraw()

or

SurfaceHolder.lockCanvas()

(see
the following sections).

现在你的Canvas将要绘制图形到这个已经定义的Bitmap上。在Bitmap上绘制之后,你能够通过

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

把你的Bitmap搬到另一个Canvas里面。推荐你使用通过View.onDraw()方法或者SurfaceHolder.lockCanvas()提供给你的Canvas绘制你最终的图形。

The

Canvas

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

drawBitmap(...)

,

drawRect(...)
,
drawText(...)

,

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上。

文档

CanvasandDrawables翻译第二集

CanvasandDrawables翻译第二集:Android官方原文地址:http://developer.android.com/guide/topics/graphics/2d-graphics.html------以下的翻译融入了自己的思考,便于理解,很多地方翻译并不是很恰当,所以配上了英文原文Draw with a Canvas 用画板(Canvas)绘制
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top