ImageData()

ImageData() 构造函数返回一个新的实例化的 ImageData 对象,  此对象由给定的类型化数组和指定的宽度与高度组成。

这个构造器是创建像这种对象首选的方式。

语法

new ImageData(array, width, height);
new ImageData(width, height);

参数

array
包含图像隐藏像素的 Uint8ClampedArray 数组。如果数组没有给定,指定大小的黑色矩形图像将会被创建。
width
无符号长整型(unsigned long)数值,描述图像的宽度。
 height
      无符号长整型(unsigned long)数值,描述图像的高度。
如果已给定数组,这个值是可选的:它将通过它的大小和给定的宽度进行推断。

示例

var imageData = new ImageData(100, 100); // Creates a 100x100 black rectangle
// ImageData { width: 100, height: 100, data: Uint8ClampedArray[40000] }

规范描述

Specification Status Comment
HTML Living Standard
ImageData()
Living Standard Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
ImageData() constructor
Experimental
Chrome Full support 42Edge Full support ≤18Firefox Full support 29IE No support NoOpera Full support 29Safari ? WebView Android No support NoChrome Android Full support 42Firefox Android Full support 29Opera Android ? Safari iOS ? Samsung Internet Android Full support 4.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

参见