简体   繁体   English

Javascript Canvas将图像绘制为仅缓冲

[英]Javascript Canvas draw image to buffer only

I'm using Canvas to process an image in various ways using it's image data only. 我正在使用Canvas仅使用图像数据以各种方式处理图像。 I'm getting the image like this: 我正在得到这样的图像:

const vid = document.querySelector('video');
const canvas = document.querySelector('canvas');
const context = canvas.getContext('2d');

But if I don't physically draw the image on the screen like this: 但是,如果我不这样在屏幕上实际绘制图像:

context.drawImage(vid, 0, 0, canvas.width, canvas.height);

then I can't process it's image data...is there any way this can all be done in data? 那我就无法处理它的图像数据...有什么办法可以全部在数据中完成? I have no use to display the image in my app at all. 我根本没有用我的应用程序显示图像。 Is there any way to draw it to the buffer only or something? 有什么办法只能将其绘制到缓冲区吗?

All I'm doing is capturing the image and then processing it's image data so I have no need to display it anywhere. 我要做的就是捕获图像,然后处理它的图像数据,因此我不需要在任何地方显示它。

You can dynamically create a canvas element using Javascript like 您可以使用Javascript动态创建画布元素,例如

var canvas=document.createElement("canvas");

get it's context 得到它的上下文

var context = canvas.getContext('2d');

and ultimately don't append it to the DOM by omitting 并最终不要通过省略将其附加到DOM

document.body.appendChild(canvas);

Even though you're still able to do all drawing operations eg drawImage() 即使您仍然能够执行所有绘制操作,例如drawImage()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM