Board index » cppbuilder » Getting RGB values from Bitmap image

Getting RGB values from Bitmap image

Hi

I'm trying to get the RGB value from a Bitmap when I move
my cursor over the image.
I have currently managed to figure out how to do this using
TColor -

//Form1 mouseMove

    TColorRef trueRGB;
    trueRGB = ColorToRGB(Form1->Color);
    Label1->Caption = GetRValue(trueRGB);
    Label2->Caption = GetGValue(trueRGB);
    Label3->Caption = GetBValue(trueRGB);

Is it possible to use the code above to get the
same value from the Bitmap?

In case, Yes - How?
In case, No - If you have an example/hint
which could guide me in the right direction,
I would be most thankfull. I'm trying to make a
palette that supports all RGB true colors, so I
wont have to use the standard ColorDialog.

Darren Wilden

 

Re:Getting RGB values from Bitmap image


On 5 Oct 2001 17:42:16 -0700, "Darren Wilden"

Quote
<darrenwil...@hotmail.com> wrote:
>I'm trying to get the RGB value from a Bitmap when I move
>my cursor over the image.

If your 'Bitmap' is a TImage, you can use its MouseMove
event and read YourImage->Canvas->Pixels[X][Y] to get
the color that's under the mouse.

void __fastcall YourForm::YourImageMouseMove
(
  TObject* Sender,
  TShiftState Shift,
  int X,
  int Y)
{

  // Get color under the mouse.
  TColor Color = YourImage->Canvas->Pixels[X][Y];

  // As an example, set the color of a TShape to
  // the current color.
  YourShape->Brush->Color = Color;

Quote
}

Take care,

Hens Zimmerman

Re:Getting RGB values from Bitmap image


Thank you very much

Darren

Re:Getting RGB values from Bitmap image


Hello Darren,

"Darren Wilden" <darrenwil...@hotmail.com> schreef in bericht
news:3bbe5368$1_1@dnews...

Quote

> Hi

> I'm trying to get the RGB value from a Bitmap when I move
> my cursor over the image.

Hmm, so you want something like the eye dropper as found in many drawing
programs?
Have a look at the TCanvas::Pixels property.
In the OnMouseMove event of your TImage do something like:

void __fastcall TForm1::Image1MouseMove(TObject *Sender, int X, int Y)
{
    TColorRef trueRGB =
ColorToRGB(Image1->Picture->Bitmap->Canvas->Pixels[X][Y]);
    Label1->Caption = GetRValue(trueRGB);
    Label2->Caption = GetGValue(trueRGB);
    Label3->Caption = GetBValue(trueRGB);

Quote
}

Obviously you'll want to set some additional conditions so the above code
only is executed when you actually want to get the bitmap colors, but I
leave that to you...;-))

Quote
> Darren Wilden

--
Greetings from overcast Amsterdam

         Jan

email: bijs...@worldonline.nl
http://home.worldonline.nl/~bijster

Re:Getting RGB values from Bitmap image


Hi Jan

Thank you very much for your advice. Yes, it is for a drawing
program ;)

Darren
___________________________
Hello from overcast Denmark

Other Threads