1# ImageData对象 2 3>  **说明:** 4> 从API version 4开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 5 6ImageData对象可以存储canvas渲染的像素数据。 7 8 9## 属性 10 11| 属性 | 类型 | 描述 | 12| -------- | -------- | -------- | 13| width | number | 矩形区域实际像素宽度。 | 14| height | number | 矩形区域实际像素高度。 | 15| data | <Uint8ClampedArray> | 一维数组,保存了相应的颜色数据,数据值范围为0到255。 | 16 17 18## 示例 19 20``` 21<!-- xxx.hml --> 22<div> 23 <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> 24</div> 25``` 26 27``` 28//xxx.js 29import prompt from '@system.prompt'; 30export default { 31 onShow() { 32 const el =this.$refs.canvas; 33 const ctx = el.getContext('2d'); 34 ctx.fillRect(0,0,200,200) 35 var imageData = ctx.createImageData(1,1) 36 prompt.showToast({ 37 message:imageData, 38 duration:5000 39 }) 40 } 41} 42``` 43