0

0

Canvas and Drawables 翻译第二集

黄舟

黄舟

发布时间:2017-01-16 16:42:41

|

1194人浏览过

|

来源于php中文网

原创


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

知料万语
知料万语

知料万语—AI论文写作,AI论文助手

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

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


相关专题

更多
C++ 高级模板编程与元编程
C++ 高级模板编程与元编程

本专题深入讲解 C++ 中的高级模板编程与元编程技术,涵盖模板特化、SFINAE、模板递归、类型萃取、编译时常量与计算、C++17 的折叠表达式与变长模板参数等。通过多个实际示例,帮助开发者掌握 如何利用 C++ 模板机制编写高效、可扩展的通用代码,并提升代码的灵活性与性能。

10

2026.01.23

php远程文件教程合集
php远程文件教程合集

本专题整合了php远程文件相关教程,阅读专题下面的文章了解更多详细内容。

29

2026.01.22

PHP后端开发相关内容汇总
PHP后端开发相关内容汇总

本专题整合了PHP后端开发相关内容,阅读专题下面的文章了解更多详细内容。

21

2026.01.22

php会话教程合集
php会话教程合集

本专题整合了php会话教程相关合集,阅读专题下面的文章了解更多详细内容。

21

2026.01.22

宝塔PHP8.4相关教程汇总
宝塔PHP8.4相关教程汇总

本专题整合了宝塔PHP8.4相关教程,阅读专题下面的文章了解更多详细内容。

13

2026.01.22

PHP特殊符号教程合集
PHP特殊符号教程合集

本专题整合了PHP特殊符号相关处理方法,阅读专题下面的文章了解更多详细内容。

11

2026.01.22

PHP探针相关教程合集
PHP探针相关教程合集

本专题整合了PHP探针相关教程,阅读专题下面的文章了解更多详细内容。

8

2026.01.22

菜鸟裹裹入口以及教程汇总
菜鸟裹裹入口以及教程汇总

本专题整合了菜鸟裹裹入口地址及教程分享,阅读专题下面的文章了解更多详细内容。

55

2026.01.22

Golang 性能分析与pprof调优实战
Golang 性能分析与pprof调优实战

本专题系统讲解 Golang 应用的性能分析与调优方法,重点覆盖 pprof 的使用方式,包括 CPU、内存、阻塞与 goroutine 分析,火焰图解读,常见性能瓶颈定位思路,以及在真实项目中进行针对性优化的实践技巧。通过案例讲解,帮助开发者掌握 用数据驱动的方式持续提升 Go 程序性能与稳定性。

9

2026.01.22

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Canvas 绘制时钟
Canvas 绘制时钟

共7课时 | 1.5万人学习

HTML5新特性基础视频教程
HTML5新特性基础视频教程

共18课时 | 3.2万人学习

HTML5 Canvas 动画实战教程
HTML5 Canvas 动画实战教程

共28课时 | 6.3万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号