博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何将文本写入HTML画布
阅读量:2521 次
发布时间:2019-05-11

本文共 1049 字,大约阅读时间需要 3 分钟。

Set the canvas size using CSS or the HTML width/height attributes to be, for example, 200 x 400:

使用CSS或HTML width / height属性将画布大小设置为例如200 x 400:

and make sure you also set the width/height properties of the canvas object in the JavaScript, to avoid the text to render blurry, for example:

并确保还设置JavaScript中canvas对象的width / height属性,以避免文本呈现模糊,例如:

canvas.width = 1800canvas.height = 1200

First thing, get a reference to a canvas

首先,获取对画布的引用

const canvas = document.querySelector('canvas')

and create a context object from it:

并从中创建一个上下文对象:

const context = canvas.getContext('2d')

Now we can call the fillText() method of the context object:

现在我们可以调用上下文对象的fillText()方法:

context.fillText('hi!', 100, 100)

Make sure the x and y coordinates of the starting point are included in the canvas size.

确保起点的x和y坐标包含在画布尺寸中。

You can pass additional properties before calling fillText() to customize the appearance, for example:

您可以在调用fillText()来自定义外观之前传递其他属性,例如:

context.font = 'bold 70pt Menlo'context.fillStyle = '#ccc'context.fillText('hi!', 100, 100)

翻译自:

转载地址:http://yhmgb.baihongyu.com/

你可能感兴趣的文章
c++课程设计之菜单选择\\
查看>>
iOS 的 XMPPFramework 简介
查看>>
hdu 3555 数位dp入门
查看>>
Git学习系列-Git基本概念
查看>>
c#多个程序集使用app.config 的解决办法
查看>>
模仿网站登录注册
查看>>
Linux+Apache+PHP+MySQL服务器环境配置(CentOS篇)
查看>>
Linux下获取本机IP地址的代码
查看>>
(C#)调用Webservice,提示远程服务器返回错误(500)内部服务器错误
查看>>
flex布局
查看>>
python-----python的文件操作
查看>>
字节流例子
查看>>
Chain Of Responsibility Design Pattern Example
查看>>
Windows下curl使用 转载
查看>>
一个简单最大正向匹配(Maximum Matching)MM中文分词算法的实现
查看>>
angularjs中$scope是什么意思?
查看>>
数据校验
查看>>
控制台输出
查看>>
设计模式(二)单例设计模式
查看>>
iOS之CAKeyframeAnimation关键帧动画详解
查看>>