Is there a MGraphics getpixel equivalent?

leafcutter's icon

I'm making v8UI which allows painting in the UI - I'd like to grab pixel colour data from the window like you can do with getpixel in LCD or getcell in jit.matrix. Is there a built in way to do this in MGraphics?

Thanks John.

TFL's icon

I don't think Mgraphics has a method to do this, but you could dump your drawing into a JitterMatrix() and getcell it. The trick is to draw your mgraphics context into an Image, and then use tonamedmatrix() onto that image.

There is an example here (it demonstrates how to do this in [v8] but that's the same approach in [v8ui]).

At the end of output_mgraphics_as_matrix() you can use matrix.getcell([x], [y]) and it will return the value of the pixel (x,y) as a 4-numbers list.

leafcutter's icon

Thanks that's a really useful response! I'm putting all the painting onto a single image anyway so this should be a nice easy solution.