Expose canvas.get_image_data

In Javascript we can use getImageData on a canvas to get raw pixels. Right now I’m jumping out to Javascript to get access to the function. It’d be nice if Anvil exposed an equivalent canvas.get_image_data call.

Or, an equivalent way to get pixel data out of an Image would also work.

2 Likes

Hi @jshaffstall - what are you looking to do? Is it something you can’t already do with the .get_image() method?

I’ve got a couple of use cases where I break out to Javascript for getImageData.

One is taking an image that has a transparent background and calculating the enclosing polygon for the non-transparent portion of the image.

The other is drawing a list of transparent images to various spots on the canvas, then taking the mouse position on the canvas and determining which non-transparent portion of an image it was clicked on.

Both of those need to examine individual pixel values in either the canvas or an image. .get_image() would be fine, if there were then a way to get ranges of pixel values from the resulting image.

This isn’t a critical thing, since I’ve got both working by breaking out to Javascript functions. It’d just be nice if that weren’t needed.

1 Like