Bitmap Colors 
Author Message
 Bitmap Colors

Is it possible to dynamically change the colors of a bitmap resource on use?
I am using buttons that use skins (from Code Guru) and it gets the skin
bitmap from a resource. I would like to use one set of bitmaps, and change
the colors based on the color of the dialog in the OnInitDlg or something.
rather than maintain 4 or 5 sets of identical Bitmaps with the only
difference being the colors.

--
Buddy Oliver
Software Engineer / Program Manager
FiberPlex Inc.



Sun, 26 Oct 2003 22:26:17 GMT  
 Bitmap Colors
Converting the in-memory image to a dib section is the way I normally use.
That way, I can specify the format for the bit array to make it easier to
manipulate the pixels.

Douglas Sutherland


Quote:
> Is it possible to dynamically change the colors of a bitmap resource on
use?
> I am using buttons that use skins (from Code Guru) and it gets the skin
> bitmap from a resource. I would like to use one set of bitmaps, and change
> the colors based on the color of the dialog in the OnInitDlg or something.
> rather than maintain 4 or 5 sets of identical Bitmaps with the only
> difference being the colors.

> --
> Buddy Oliver
> Software Engineer / Program Manager
> FiberPlex Inc.




Sun, 26 Oct 2003 23:26:39 GMT  
 Bitmap Colors
Hello Douglas,

Could you please tell me where I could get the sample(source code) of
setting the color of certain bits in a DIB?

Thanks very much.

yhhuang
ICQ:91074870



Mon, 27 Oct 2003 09:16:26 GMT  
 Bitmap Colors
I just wrote it myself. I'm sure there are samples in the internet somewhere
but I don't know where exactly...

Here is how I create the dib section...

  // Create the dib section
  m_hImage = ::CreateDIBSection(
     pSourceDC->m_hDC, // handle to device context
     &m_bmiImage,      // pointer to structure containing bitmap size,
        // format, and color data
     DIB_RGB_COLORS,   // color data type indicator: RGB values or
        // palette indexes
     (PVOID *)&m_pImageBits,  // pointer to variable to receive a pointer to
        // the bitmap's bit values
     (HANDLE)0,        // optional handle to a file mapping object
     (DWORD)0);        // offset to the bitmap bit values within the
        // file mapping object

I set up the m_bmiHeader in the class constructor like this:

 m_bmiImage.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 m_bmiImage.bmiHeader.biWidth = 0;
 m_bmiImage.bmiHeader.biHeight = 0;
 m_bmiImage.bmiHeader.biPlanes = 1;
 m_bmiImage.bmiHeader.biBitCount = 24;
 m_bmiImage.bmiHeader.biCompression = BI_RGB;
 m_bmiImage.bmiHeader.biSizeImage = 0;
 m_bmiImage.bmiHeader.biXPel{*filter*}eter = 0;
 m_bmiImage.bmiHeader.biYPel{*filter*}eter = 0;
 m_bmiImage.bmiHeader.biClrUsed = 0;
 m_bmiImage.bmiHeader.biClrImportant = 0;

Notice the bitcount is 24, so the r,g, and b values are byte aligned so I
can write to them easier.

Then this is how I write to them:

// Set the new pixel value in the dest
*(m_pImageBits + nImagePixelOffset) = ucBlue;
*(m_pImageBits + nImagePixelOffset+1) = ucGreen;
*(m_pImageBits + nImagePixelOffset+2) = ucRed;

Easy enough. The pixel offset is

nImagePixelOffset = (scan line which is the y value)*nImageBytesWidth +
(pixel column which is the x value)*3;

The only thing is you have to make sure the scan line is a multiple of 4
wide. I do that like this

int nImageBytesWidth = ActualBitmapWidth*3;
if (nImageBytesWidth % 4) nImageBytesWidth += (4 - nImageBytesWidth %4);

It's really not too bad. I'm not really messing with the color table at
all - since it is a 24 bit per pixel the pixel byte values themselves hold
the color values.

Hope this helps you...

Douglas Sutherland


Quote:
> Hello Douglas,

> Could you please tell me where I could get the sample(source code) of
> setting the color of certain bits in a DIB?

> Thanks very much.

> yhhuang
> ICQ:91074870



Mon, 27 Oct 2003 10:15:07 GMT  
 Bitmap Colors
Great. Thanks very much.


class, which provides a convenient wrapper around a DIBSection.  It'll help
you out with computing the addresses of the pixels, which can be slightly
tricky because you have to worry about alignment of the rows and two
possible orientations of the bits (top-down and bottom-up).

yhhuang
ICQ:91074870



Mon, 27 Oct 2003 11:27:31 GMT  
 Bitmap Colors
Thanks. I'll have to look into that.

Douglas Sutherland


Quote:
> Great. Thanks very much.


> class, which provides a convenient wrapper around a DIBSection.  It'll
help
> you out with computing the addresses of the pixels, which can be slightly
> tricky because you have to worry about alignment of the rows and two
> possible orientations of the bits (top-down and bottom-up).

> yhhuang
> ICQ:91074870



Mon, 27 Oct 2003 12:37:16 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How to adjust a bitmap color

2. Modify bitmap color

3. Bitmap Color Change when I changed from Windows 98 to Windows 2000

4. Change bitmap colors when cut item from tree control

5. Bitmap color

6. BITMAP color problem!

7. Bitmap, Colors

8. Bitmap color masking

9. Changing Bitmap Colors

10. CBitmapButtons changing bitmap colors??

11. Copy bitmap colors to array

12. toolbar bitmap colors

 

 
Powered by phpBB® Forum Software