我能够生成一个新ImageData
对象,但无法将其渲染到画布上下文。出于某种原因,画布 2d 上下文不喜欢它创建的 ImageData 对象。
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var width = 50;
var height = 50;
var ci = ctx.createImageData(width,height); // ImageData { width: ..., height: ..., data: Uint8ClampedArray(10000) }
// Draw on ci ImageData object...
ctx.drawImage(ci, 0, 0, width, height);
但是,这会引发错误:
TypeError: Argument 1 of CanvasRenderingContext2D.drawImage could not be converted to any of: HTMLImageElement, SVGImageElement, HTMLCanvasElement, HTMLVideoElement, ImageBitmap.