Board index » cppbuilder » RGB in the Bitmap->Pen?

RGB in the Bitmap->Pen?

I'm fairly new to programming in C++.  I'm working on a paint program, but
have stumbled into problems trying to specify the RGB values of the Pen.  It
seems that all I can use is named colors, unless I go to the WinAPI.  I've
tried creating a pen using the API SelectObject and CreatePen functions, but
can't get it to assign to the Pen of a TBitmap.

Could anyone help me, or point me to info on the Web?

Thanks in advance,
Lonnie

 

Re:RGB in the Bitmap->Pen?


Lonnie,

Quote
> I'm fairly new to programming in C++.  I'm working on a paint program, but
> have stumbled into problems trying to specify the RGB values of the Pen.  It
> seems that all I can use is named colors, unless I go to the WinAPI.  I've
> tried creating a pen using the API SelectObject and CreatePen functions, but
> can't get it to assign to the Pen of a TBitmap.

You can use the RGB macro to specify the intensities of the red, green,
and blue values (0 - 255) of a color, then simply assign it to you
Bitmap's Canvas::Pen::Color property...

//white
MyBitmap->Canvas->Pen->Color = (TColor)RGB(255, 255, 255);

//aqua
MyBitmap->Canvas->Pen->Color = (TColor)RGB(0, 255, 255);

//black
MyBitmap->Canvas->Pen->Color = (TColor)RGB(0, 0, 0);

HTH.

->Damon
-------------------------------------
http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>

Re:RGB in the Bitmap->Pen?


First off, thanks for the help, Damon.  Second, I've tried that and found it
too slow.  What I'm creating is a color-picker, similar to the GIMP (linux)
or Photoshop's.  I've got the colors to work right with a test script, but
it refreshes too slow.  I know the help said doing by pixels was 1000x
slower than scanline, so I'm trying to understand scanline, but can't find
any decent help.  I'm using BCB 3.

Here's the current code I'm using...

// Draw the Red ColorField...
            for (int y = 0; y < 256; y++) {
                for (int x = 0; x < 256; x++) {
                    BitCField->Canvas->Pixels[x][y] = (TColor) RGB(x, y,
255);
                }
                BitCField->Canvas->Pixels[0][y] = (TColor) RGB(0, y, 255);
            }
            imgColorField->Picture->Graphic = BitCField;

Is it possible to apply Scanline to this, or do I need to learn the API
functions to do it?

Thanks to any who can help in advance..
Lonnie

Re:RGB in the Bitmap->Pen?


Quote
Lonnie Ezell wrote:
> Here's the current code I'm using...

> // Draw the Red ColorField...
>             for (int y = 0; y < 256; y++) {
>                 for (int x = 0; x < 256; x++) {
>                     BitCField->Canvas->Pixels[x][y] = (TColor) RGB(x, y,
> 255);
>                 }
>                 BitCField->Canvas->Pixels[0][y] = (TColor) RGB(0, y, 255);
>             }
>             imgColorField->Picture->Graphic = BitCField;

> Is it possible to apply Scanline to this, or do I need to learn the API
> functions to do it?

Lonnie,

    Here's some code that draws the colormap onto a temporary bitmap and then
draws that bitmap onto the form's canvas.  Hopefully this gives you enough to
get started.

 Graphics::TBitmap* tempBMP=new Graphics::TBitmap;
 tempBMP->Width=256;
 tempBMP->Height=256;
 tempBMP->PixelFormat=pf24bit;  //make sure this is a 24-bit bitmap
 for (int row=0;row<256;row++)
  {
   BYTE* scanPtr=(BYTE*)tempBMP->ScanLine[row];  //get pointer to the current
row

   for (int col=0;col<256;col++)
    {
     BYTE* tempPtr=scanPtr+col*3;  //get pointer to the first of the three bytes
for the current pixel
     tempPtr[0]=col;  //blue byte
     tempPtr[1]=row; //green byte
     tempPtr[2]=255; //red byte
    }
  }

 Canvas->Draw(0,0,tempBMP);
 delete tempBMP;

--
Alan McIntyre
a...@norfolkgraphics.com
http://norfolkgraphics.com

Re:RGB in the Bitmap->Pen?


Quote
Lonnie Ezell <lez...@axs.net> wrote in message

news:7h898n$n1k12@forums.borland.com...

Quote
> I'm trying to understand scanline, but can't find
> any decent help.  I'm using BCB 3.

Here's a (Delphi) Tech Note about Scanline:
www.efg2.com/lab/ImageProcessing/Scanline.htm

efg
________________________________
efg's Computer Lab:       www.efg2.com/lab
Delphi Books:  www.efg2.com/lab/TechBooks/Delphi.htm

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

Re:RGB in the Bitmap->Pen?


Just wanted to say thanks for everyone and their help...whenever I get this
Color Picker finished I'll make a component from it and post it online.
sort of repayment, I suppose....

Thanks again,
it all works great,
Lonnie

Other Threads