在 HTML5 画布上画一个点 [英] Drawing a dot on HTML5 canvas

查看:31
本文介绍了在 HTML5 画布上画一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 context.moveTo()context.lineTo() 函数在 HTML5 画布上画一条线非常简单.

Drawing a line on the HTML5 canvas is quite straightforward using the context.moveTo() and context.lineTo() functions.

我不太确定是否可以绘制一个点,即为单个像素着色.lineTo 函数不会绘制单个像素线(显然).

I'm not quite sure if it's possible to draw a dot i.e. color a single pixel. The lineTo function wont draw a single pixel line (obviously).

有没有办法做到这一点?

Is there a method to do this?

推荐答案

出于性能原因,如果可以避免,请不要画圆.只需绘制一个宽和高为 1 的矩形:

For performance reasons, don't draw a circle if you can avoid it. Just draw a rectangle with a width and height of one:

ctx.fillRect(10,10,1,1); // fill in the pixel at (10,10)

这篇关于在 HTML5 画布上画一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆