explenation

Général

Mrrrtijn

il y a 5 ans

Hi all,

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

maybe some example code?

Thnx in advance

Thierry

NEW il y a 5 ans

Could you be more precise?

Documentation is simple on this one, but the method is simple in itself I believe.
https://gamebuino.com/fr/academy/reference/image-getpixelindex

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

Mrrrtijn

NEW il y a 5 ans

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() {
while(!gb.update());
gb.display.clear();

gb.display.setColor(WHITE);
gb.display.drawLine(10,10,30,10);
String PixColor = String ('gb.display.getPixelColor(const int16_t 10,const int16_t 10)');
gb.display.setCursor(20,40);
gb.display.setColor(WHITE);
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....

Steph

il y a 5 ans

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.

Thierry

NEW il y a 5 ans

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)

or

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?


Steph

NEW il y a 5 ans

Mrrrtijn Mrrrtijn

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.

Mrrrtijn

il y a 5 ans

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

Mrrrtijn

NEW il y a 5 ans

Hi Steph, 


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

Mrrrtijn

NEW il y a 5 ans

Steph Steph

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

Steph

NEW il y a 5 ans

That was my goal ;-)