Board index » cppbuilder » Bitmap RGB Values

Bitmap RGB Values

At present, I am working on a project which involves low level graphics
work. My original intention was to work with 8-bit bitmap files
(although I could work with 24-bit files if the lack of palette makes
things more straight forward) and was hoping CPP Builder would make it
fairly easy to read and set the RGB values of individual pixels. This
doesn't seem to be the case however.

This problem has been mentioned before in this newsgroup, but the
suggested web page involved Delphi, which I have never touched in my
life.

If anyone can recommend a good book/site which would help me out, I
would really appreciate it.

Al

 

Re:Bitmap RGB Values


Hi Alan,

Quote
> At present, I am working on a project which involves low level graphics
> work. My original intention was to work with 8-bit bitmap files
> (although I could work with 24-bit files if the lack of palette makes
> things more straight forward) and was hoping CPP Builder would make it
> fairly easy to read and set the RGB values of individual pixels. This
> doesn't seem to be the case however.
> If anyone can recommend a good book/site which would help me out, I
> would really appreciate it.

Working with 24-bit image is generally easier, as palette management can
become a hassle.  If you have BCB3+ then I highly recommend the ScanLine
property.  This is direct access to the bits of the Bitmap (Windows
DIBSection holds these bits in a memory mapped file).  Alan McIntyre has
some good sample projects on the ScanLine property...

http://norfolkgraphics.com/bcb.html

Good luck!

Damon C.

Re:Bitmap RGB Values


BTW, if you have BCB1, then you can use DIBSections via the API.  It
really is very straighforward, so let me know if you need an example.

Good luck again.

Damon

Re:Bitmap RGB Values


Hai Alan,
    There is a very simple way to read RGB value.
    declare a class like this :
class c24BitPixelColor
{
   public :

        //The order of the variables are criticle!
        unsigned char Blue;
        unsigned char Green;
        unsigned char Red;

Quote
};

Then, for example, to change the image to white:( this = TBitmap)

   c24BitPixelColor *Pixel;

   for (int y = 0; y < this->Height; y++)
   {
      //Select a line
      Pixel = (c24BitPixelColor *) this->ScanLine[y];

      //Slide through the columns
      for (int x = 0; x < this->Width; x++)
        {
        Pixel[x].Red = 255;
        Pixel[x].Green = 255;
        Pixel[x].Blue = 255;
        }
    }

Good luck!
Norman

Quote
> At present, I am working on a project which involves low level graphics
> work. My original intention was to work with 8-bit bitmap files
> (although I could work with 24-bit files if the lack of palette makes
> things more straight forward) and was hoping CPP Builder would make it
> fairly easy to read and set the RGB values of individual pixels. This
> doesn't seem to be the case however.

Re:Bitmap RGB Values


Thanks for your help guys.

Al

Re:Bitmap RGB Values


Quote
>class c24BitPixelColor
>{
>   public :

>        //The order of the variables are criticle!
>        unsigned char Blue;
>        unsigned char Green;
>        unsigned char Red;
>};

Two comments. First, you should ensure that this structure is byte aligned
using #pragma pack. Secondly, the windows header files alread include a
structure for this. Its called RGBTRIPLE, and its declare in wingdi.h

#include <pshpack1.h>
typedef struct tagRGBTRIPLE {
        BYTE    rgbtBlue;
        BYTE    rgbtGreen;
        BYTE    rgbtRed;

Quote
} RGBTRIPLE;

#include <poppack.h>

Unfortunately, the member names are kind of cryptic. Notice that the windows
header file protects against alignment problems.

Harold Howe [TeamB]
http://www.bcbdev.com

Other Threads