Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[html] 第256天 canvas画出来的图是位图还是矢量图? #1702

Open
haizhilin2013 opened this issue Dec 27, 2019 · 2 comments
Open
Labels
html html

Comments

@haizhilin2013
Copy link
Collaborator

第256天 canvas画出来的图是位图还是矢量图?

我也要出题

@haizhilin2013 haizhilin2013 added the html html label Dec 27, 2019
@rivercome
Copy link

canvas画出来的图是位图
SVG是矢量图

@Wyt-GitHub8000
Copy link

Canvas 画出来的图是位图,也就是像素图。Canvas API 中的绘制方法实际上是通过对像素进行操作来完成的,它并不支持矢量图形,所有的图形都是由像素点组成的。

当使用 Canvas 绘制图形时,我们可以通过设置 Canvas 元素的宽度和高度来指定绘制区域的像素大小,每个像素的颜色和位置都是确定的,这样就可以画出各种复杂的图形和图像。但是由于 Canvas 画出来的图形是由像素组成的,所以在缩放或放大时会失去图形的清晰度,因为像素本身是不可伸缩的。

与 Canvas 不同的是,矢量图形是由数学公式描述的,它不依赖于像素,而是根据矢量图形的描述信息在渲染时进行计算和绘制,所以可以在任意缩放倍数下保持图形的清晰度。矢量图形可以用 SVG 技术实现,也可以在一些绘图软件中创建和编辑,例如 Adobe Illustrator、CorelDRAW 等。

因此,如果需要绘制可以任意缩放的图形,可以使用矢量图形技术;如果需要绘制复杂的像素级别的图像或者动态图像,可以使用 Canvas 绘图技术。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
html html
Projects
None yet
Development

No branches or pull requests

3 participants