博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小程序 画布未加载_如何在HTML画布中加载图像
阅读量:2519 次
发布时间:2019-05-11

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

小程序 画布未加载

I was using the npm package to draw an image server-side using the Canvas API.

我正在使用 npm包通过Canvas API绘制服务器端图像。

Note: this is how to work with images in a canvas in Node.js, not in the browser. In the browser it’s different.

注意:这是在Node.js(而不是浏览器)中使用画布中的图像的方法。 在浏览器中是不同的。

Load the loadImage() function

加载loadImage()函数

const { createCanvas, loadImage } = require('canvas')

Create the canvas:

创建画布:

const width = 1200const height = 630const canvas = createCanvas(width, height)const context = canvas.getContext('2d')

Then call loadImage(), which returns a promise when the image is loaded:

然后调用loadImage() ,在加载图像时返回一个promise:

loadImage('./logo.png').then(image => {})

You can also use, inside an async function:

您还可以在异步函数中使用:

const image = await loadImage('./logo.png')

Once you have the image, call drawImage and pass it with the x, y, width and height parameters:

获得图像后,调用drawImage并将其与x,y,width和height参数一起传递:

context.drawImage(image, 340, 515, 70, 70)

翻译自:

小程序 画布未加载

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

你可能感兴趣的文章
多线程基础
查看>>
完美解决 error C2220: warning treated as error - no ‘object’ file generated
查看>>
使用SQL*PLUS,构建完美excel或html输出
查看>>
SQL Server数据库笔记
查看>>
X-Forwarded-For伪造及防御
查看>>
android系统平台显示驱动开发简要:LCD驱动调试篇『四』
查看>>
Android 高仿微信头像截取 打造不一样的自定义控件
查看>>
Jenkins的初级应用(1)-Publish Over SSH
查看>>
利用正则表达式群发定制邮件
查看>>
【原】RDD专题
查看>>
第三周——构建一个简单的Linux系统MenuOS
查看>>
Docker 的两类存储资源 - 每天5分钟玩转 Docker 容器技术(38)
查看>>
Codeforces 257D
查看>>
常用的20个强大的 Sublime Text 插件
查看>>
ajaxfileupload.js在IE中的支持问题
查看>>
tensorflow学习之(十)使用卷积神经网络(CNN)分类手写数字0-9
查看>>
当document.write里含有script标签时
查看>>
工作中常见问题
查看>>
JAVA 从一个List里删除包含另一个List的数据
查看>>
外国的月亮比较圆吗?外籍团队工作有感
查看>>