Explenation - By Mrrrtijn

Author :  Mrrrtijn

Hi all,

can please somebody explain me how to use  :   Image::getPixelIndex

maybe some example code?

Thnx in advance

Author :  Thierry

Could you be more precise?

Documentation is simple on this one, but the method is simple in itself I believe.

Maybe you can explain what you are doing and it will help to understand what you don't understand.

Author :  Mrrrtijn

Hi Thierry,

Thank you, 

 I understand that with. ' ColorIndex Image::getPixelIndex( int16_t x , int16_t y )'. the color of the pixel is returned. 

but how do I write thew code for it ? 

I tried something like this:

#include <Gamebuino-Meta.h>

void setup() { gb.begin(); }

void loop() {

String PixColor = String ('gb.display.getPixelColor(const int16_t 10,const int16_t 10)');
gb.display.print(PixColor);  }

it did print the color on the screen but only this : 540094505.  When I change the color of the line, it returns the same numbers. I would like it to return the color. 

Who can help me out? I am not really experienced yet....

Author :  Thierry

First, when you post code, select it and use the 5th icon "Inline Code" it is easier to read.

I don't get what you want to achieve with your code.

Here are my thoughts.

If you want to get the color from the pixel at coordinates (10, 10), try to use simply:

gb.display.getPixelColor(10, 10)


gb.display.getPixelIndex(10, 10)

Looks at both documentation. 

First one gets the color of the pixel, the second one gets the indexed color.

Check the Academy called "Add images to your game" to understand the difference.

Then, I don't get what you wanted but I guess that you draw a line using White, then you pick the Color at the begining of this line.

You will end with the WHITE Color.

What else would you like to do with this color?

Author :  Steph

Hello Mrrrtijn,

Here is a code example that should help you.

A flashing white spot is initialized in the center of the screen. You can move it with the handheld's PAD. The Color and ColorIndex of the pixel on which it is located are displayed at the top of the screen.

Hopefully that will answer your questions.

Author :  Mrrrtijn

Hi Steph, 

thank you, that is very kind. I'm going to take a look at it now! thx again!

Author :  Mrrrtijn

this is very helpful. I will learn a lot from this!

Author :  Steph

That was my goal ;-)