Help getting RGB Values using GetBackgroundPixelColor

Hello all,

I have been stuck on a problem with getting RGB values from a canvas image that is 32x32.
rainbow-grid

When I run through a For loop to try and extract the first line of values (on the y axis) it gets values but they are strange. The first red value on the top left should be 255, and the second 195, the third 255 and this should alternate for at least 10 pixels. The values I get reported back are:

255
255
255
195
195
195
195
255
255
255
255
195

If I increase the y position by 4 it kind of works but this seems logically incorrect.

Any help would be greatly be appreciated. This has had me stuck for days and I have reduced this down to testing on a simple button and canvas screen with a ListView.

Jae

Screenshot of returned values:

I see a periodic variation in your image under an IrfanView zoom:

You image has horizontal banding in it, 32 of them by rough count.

P.S. the properties match your description:

How was that image generated?

1 Like

Hello and thanks for the reply.

Yes,the banding is supposed to be there (every 2nd pixel) I was trying all sorts of variants to a 32x32 image. I want to write the RGB values to a series of 32 RGB LEDS so in essence, each pixel would be referenced in the LED. I put the banding in to get alternative values to ensure the read was correct as it seems to resemble what the image has. Here's some other (often cobbled together in paint) trials.

rainbow-flat chipko_newTest2 colourtest5 chipko_newTest chipko_skywrite whitedot

It has problems with all the 32x32 bit PNGJPG files I've given it and it could be something I'm jsut doing wrong (I have even specified the 32px dimensions for the canvas and not automatic).

I believe whenever I used canvas touch it should be correct but seemingly when I iterate through co-ordinates it doesn't work.

Why not just generate a list with the values you want ?

I try that, I generate a list but the first 4 values represent pixel 1 (top left), and the next four or so pixel 2.

I have tried just reading a single pixel, and I have tried generating lists. I even partly dissected someone who did a canvas image to foreground (though to be honest, I need to do more on that).. Each time I egnerate a list, the RGB values are off. I have even read about the PixelColor as opposed to the background pixel colour, tried with a ball, without. I'm just aboslutely lost as to why I am not getting an accurate RGB reading over each pixel

I downloaded your first image, and applied it to my convert canvas to foreground aia project, adding another list to just get the red values, this is what it returned for every pixel, working vertically
x=1 y=1,x=1 y=2 and so on
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 226, 226, 227, 255, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 226, 226, 227, 255, 111, 111, 111, 111, 111, 111, 110, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 110, 110, 110, 110, 110, 110, 111, 111, 111, 111, 111, 110, 255, 111, 111, 111, 111, 111, 111, 110, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 110, 110, 110, 110, 110, 110, 111, 111, 111, 111, 111, 110, 255, 55, 55, 55, 56, 55, 55, 55, 56, 56, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 56, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 255, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 255, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 255, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 255, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 255, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 111, 112, 112, 112, 112, 112, 111, 111, 112, 112, 112, 112, 112, 112, 111, 111, 112, 255, 179, 179, 179, 179, 179, 179, 179, 180, 180, 180, 180, 180, 179, 179, 179, 180, 180, 179, 179, 179, 180, 180, 179, 180, 180, 179, 179, 179, 179, 179, 179, 255, 179, 179, 179, 179, 179, 179, 179, 180, 180, 180, 180, 180, 179, 179, 179, 180, 180, 179, 179, 179, 180, 180, 179, 180, 180, 179, 179, 179, 179, 179, 179, 255, 237, 237, 237, 237, 237, 237, 237, 236, 236, 236, 236, 237, 237, 237, 237, 236, 236, 237, 237, 237, 236, 236, 237, 236, 236, 237, 237, 237, 237, 237, 237, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]

That sounds painful.

Are you the Metric Rat Ai2 by any chance?

Could you please share with how you did that if you dont mind. This has had me confused for a few days now .. Thank you in advance.

@ABG - I didn't feel the pain :smiley

@TIMAI2 When you said first image, I take it you mean the first image from the 2nd set (the rainbow) as I couldnt see the value R=195 in that list and was confused. I must thank you for your canvas image to foreground as that was the inspiration to keep trying. I need to work out how to extract the details and will try again

Thank you all for the help - clearly I ned to work on addressing the values from a big poixel array :stuck_out_tongue:

Sorry, have had a handful of other things going on this morning.

See attached aia project

CanvasImageToForegroundGetReds.aia (5.9 KB)

run this in companion, then you can view the contents of the variable list "pixelredlist" to see the red values returned. You can apply different images without too much difficulty.

1 Like

A very nice thing for generating images on rgb matrices

@TIMAI2 You don't need to apologise! I must apologise for being a headache!

Thanks for sharing your .aia - I still seem to have an issue. I have tried to put it into a simple app to show what I am seeing (it might be scaling, or something which I don't understand). When I get pixel 1,1 (x,y) it returns 255 - great, when I use the grid image (see below) and I choose x=1, y=2 it still shows 255.

When I choose x as 1 and y as 4, then it returns 195.

This is the base 32x32 image enlarged to show the red values


getPixelColour.aia (11.8 KB)

Sorry for being a pain :stuck_out_tongue:

The .aia project you shared works fine for me. I typed x = 1 and y = 2, it returns the color 195 23 23

2 Likes

A couple of things:

It is possible that the x,y range starts from 0,0 not 0,1

so use 0-31 instead of 1-32 in the for each blocks

I believe that the canvas is doing approximations of colour when getting the colour of a pixel, which is why it is returning odd values. I even tried an example with only 12 pixels in an image and it still wouldn't return correctly. It could also be that different computers/emulators are returning different results. Hopefully a canvas expert can advise....

2 Likes

Can I have your android device then please?!
@TIMAI2 - good point. I was trying with 0,0 originally but then realised I think it references different to what I am used to. It would seem that it works for some people which is odd. Good call on the approximation and hopeully a canvas expert might be able to help @Italo

I might try another device and see if it works.- I am just completely stuck.

Samsung S8, android9. I tried with companion.

1 Like

Experiment with screen resolution in display settings. This stops working when the resolution is increased. Maybe some artificial pixels are formed with higher resolution.

2 Likes

That'#s a great suggestion. Interestingly I had a spare phone a Samsung J6 and that worked when I referenced from 0,0 - the other phone is an S7 Edge - interesting that they work differently biut at least I could potentially continue my development of the app now (bearing in mind that it wont work as planned on all devices!)

Hige thanks to @Patryk_F and @TIMAI2 for massively helping. Maybe I need to move this to a bug section?

I did a little searching for the internal mysteries of the ,png file format.
I stumbled upon a specification for interlaced data, which sounds like those alternating color bands of your image:
http://www.libpng.org/pub/png/spec/1.2/PNG-DataRep.html#DR.Interlaced-data-order

Are you prepared to do a deep dive into the .png file specification?

Are you able to make a 256x256 rainbow grid. be interested to see if having more pixels make a difference? e.g. instead of 1x1 = 1 pixel with 255 you have 8x8 = 64 pixels with 255. This can be managed down to your 32x32 if it works in the app.

1 Like