English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The read-only ImageData.width property returns the number of pixels in each row of the image data object.
Remind the width of the ImageData object:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML canvas imgData width属性使用-基础教程(oldtoolbag.com)</<title> </<head> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); var imgData = ctx.createImageData(100, 100); alert("Width of imgData is: " + imgData.width); var i; for (i = 0; i < imgData.data.length; i += 4) { ] = 0;+0] = 255; ] = 0;+1] = 0; ] = 0;+2] = 0; ] = 0;+3imgData.data[i 255; } ctx.putImageData(imgData, 10, 10); </script> </body> </html>Test to see ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 9Firefox, Opera, Chrome, and Safari support ImageData width property.
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.
This property returns the width of the ImageData object (in pixels).
Tip:Please see createImageData(),getImageData() andputImageData() method, for more information about the ImageData object.
JavaScript syntax: | imgData.width; |
---|