“ canvas1.getContext不是函数”;通过XmlService创建画布元素时出错 [英] "canvas1.getContext is not a function" error when creating a canvas element via XmlService

查看:111
本文介绍了“ canvas1.getContext不是函数”;通过XmlService创建画布元素时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Google Apps Script开发项目,但是遇到了问题。


我目前正在尝试使用HTML画布获取图像的单个像素(如果您知道从JS图片中获取像素数据的另一种方法,请告诉我)。问题是,Google Apps脚本似乎没有用于画布的getContext方法。我不确定这是否是有目的的,还是某种错误。


代码:

  var img = XmlService.createElement('img'); 
img.src =查询;
var canvas1 = XmlService.createElement(’canvas’);
var context = canvas1.getContext(’2d’);

错误:


TypeError:canvas1.getContext不是功能(第8行,文件代码)


我不确定如何解决或解决此问题。

解决方案

画布元素您的要求是 Canvas API 的一部分。 p>

Google Apps脚本不包含canvas元素的功能,实际上它不包含任何Web API元素的功能。


XMLService Service具有类元素,即


XML元素节点的表示形式。



I have been working on making projects inside Google Apps Script but came across a problem.

I am currently trying to get the individual pixels of an image, by using an HTML canvas(if you know of another way to get pixel data from an image in JS, please let me know). The problem is, Google Apps Script doesn't seem to have a getContext method for the canvas. I'm not sure if this is done purposely, or if it is some kind of bug.

Code:

var img = XmlService.createElement('img');
img.src = query;
var canvas1 = XmlService.createElement('canvas');
var context = canvas1.getContext('2d');

Error:

TypeError: canvas1.getContext is not a function (line 8, file "Code")

I am not sure how to fix or get around this.

解决方案

The "canvas element" your are asking for is part of Canvas API.

Google Apps Script doesn't include functions for the canvas element, actually it doesn't include any function for any Web APIs elements.

The XMLService Service has the Class Element, this is

A representation of an XML Element node.

这篇关于“ canvas1.getContext不是函数”;通过XmlService创建画布元素时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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