Re: Populating CBitmap
Hi Joseph,
Thanks for your reply and your excellent essays on bitmap.
After reading your samples, I've decided to populate the CBitmap in the
following way. What do you think?
/////////////////////////////////////////////////////////
BITMAP bm_struct;
bm_struct.bmType = 0;
bm_struct.bmWidth = m_bmi->bmiHeader.biWidth;
bm_struct.bmHeight = m_bmi->bmiHeader.biHeight;
bm_struct.bmWidthBytes =
m_bmi->bmiHeader.biSizeImage/m_bmi->bmiHeader.biHeight);
bm_struct.bmPlanes = 1;
bm_struct.bmBitsPixel = bm_struct.bmWidthBytes/m_bmi->bmiHeader.biWidth * 8;
bm_struct.bmBits = m_bitmap; //BYTE Array
CBitmap bm;
if (bm.CreateBitmapIndirect(&bm_struct))
{
// I've populated the CBitmap.
}
/////////////////////////////////////////////////////////
"Joseph M. Newcomer" wrote:
You should not use char* to represent an array of bytes; you should use unsigned char *,
or BYTE*, or LPBYTE. This makes it clear that the data is unsigned byte data (colors run
0..255,but if you use char, your colors run 0..127 then -127..-1 in that order, and will
be sign-extended which makes no sense because all byte values are supposed to be unsigned.
In general, you should forget the char and char* data types exist except in the most rare
and exotic situations, of which htis is not an example)
See my essays on bitmaps on my MVP Tips site.
joe
On Mon, 25 Aug 2008 23:25:01 -0700, Charles Tam <CharlesTam@discussions.microsoft.com>
wrote:
Hi, I'm quite new in CBitmap and was wondering how to populate a CBitmap
given the followings:
(a) char* of bitmap bits (array of bytes).
(b) BITMAPINFO of bitmap data.
These data are set already written by someone else.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm