问题描述
javascript中是否有函数返回画布中图像对象占用的像素数组?无论如何返回画布中图像对象占用的像素列表?
Is there a function in javascript to return an array of pixels taken up by an image object in canvas? Is there anyway to return a list of pixels taken up by an image object in canvas?
推荐答案
你可以调用.getImageData( )在上下文中获取像素值。你告诉它画布中的坐标来抓取像素,它会返回一个高度,宽度和像素的对象。像素是整数数组,因此每个像素占4(红色,绿色,蓝色,alpha)。因此,数组中有高度*宽度* 4像素。
You can call ".getImageData()" on the context to get pixel values. You tell it the coordinates within the canvas to grab pixels from, and it gives you back an object with height, width, and pixels. The pixels are an array of integers, such that each pixel takes up 4 (red, green, blue, alpha). Thus there are height * width * 4 pixels in the array.
是该主题的MDC页面。
Here is the MDC page on the topic.
这篇关于返回画布对象的像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!