Draw with a 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.

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 fromSurfaceHolder.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:

Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
//like c.drawable(xx,xx,xx.xx)
return 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 byView.onDraw() or SurfaceHolder.lockCanvas() (see the following sections).

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.

免责声明:文章转载自《Draw with a Canvas》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇第一步(搭建阿里云主机服务器): 如何在远程Linux服务器上搭建Nginx保持VISUAL STUDIO控制台驻留不闪退下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

android性能优化练习:过度绘制

练习:https://github.com/zhangbz/AndroidUIPorblems 查看过度绘制 在开发者选项中开启"调试GPU过度绘制" 判断标准 无色:没有过度绘制,即只绘制了一次 蓝色:一倍过度绘制 绿色:二倍过度绘制 淡红色:三倍过度绘制 红色:四倍或以上过度绘制 实践 其中"This is test"四次或以上倍数过度绘制,其背景三...

WPF在圆上画出刻度线

思路 我们可以使用Ellipse先画出一个圆当背景,然后用Canvas再叠加画上刻度线,就能得到如下的效果 我们先用Ellipse画一个橙色的圆,然后将Canvas的宽度和高度绑定到Ellipse的宽度和高度 <Grid> <Ellipse Fill="Orange" Width="400" Height="400" N...

前端知识小总结2

(暂时撇开内容、样式、行为的分离) 一: 1-语义化及语义化标签 标签的语义化,是指在看到标签名的情况下基本能理解它所代表的含义,比较直观,便于浏览器的解析和阅读。 语义化的优点, (1)为了在没有css的情况下,页面也能呈现出很好地内容结构、代码结构(2)有利于用户体验(3)有利于SEO和搜索引擎建立良好的沟通。(4)方便其他设备解析以意义的方式来渲染网...

当微信小程序遇到AR(三)

当微信小程序遇到AR,会擦出怎么样的火花?期待与激动...... 通过该教程,可以从基础开始打造一个微信小程序的AR框架,所有代码开源,提供大家学习。 本课程需要一定的基础:微信开发者工具,JavaScript,Html,Css 第三章:基石-接入Three.js 【前情提要】 上一章,我们已经可以在微信小程序中访问摄像头,并且获得每一帧的数据了。接下...

Html 5 版 电子时钟

效果图: html 5 canvas元素  Html 5的canvas元素可以用于在网页上绘制图形[即canvas的作用]。 canvas画布使用JavaScript在网页上绘制图形 其拥有绘制各种路径,矩形,圆,字符以及添加图像的方法。 (1)在body中创建canvas元素 <canvas id="panel" width="500" heig...

Canvas 全局不透明度和全局图像重叠设置

全局不透明度 globalAlpha globalAlpha = 1 (Default) var canvas = document.getElementById('canvas') canvas.width = 1200; canvas.height = 800; var context = canvas.getContext(...