Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using CreateDIBSection()

Status
Not open for further replies.

bkelly13

Programmer
Aug 31, 2006
98
US
My project inputs a telemetry stream that includes a real time image. From various places I have put together some code that seems like it should create a DIB and be ready to use. But the call to CreatDIBSection leaves my_bitmap and the pointer ppvBits both set to zero. The GetLastError returns zero indicating no error.

The project is a Win32 application under Visual Studio 2008, C++, with SDI and MFC enabled. Eventually this will become part of an ActiveX project, but for now I am just trying to write bits to the screen.

What have I done wrong here?

Code:
const int IMAGE_ROW_COUNT    = 120;
const int IMAGE_COLUMN_COUNT = 120;
const int BYTES_PER_PIXEL    = 3;  // unknown, presume 3, one each RBG, change later
const int RGB_THREE_BYTES_PER_PIXEL = 24;

BITMAPINFO       my_bit_map_info;
BITMAPINFOHEADER my_bit_map_info_header;
RGBQUAD          my_rgb_quad;
HBITMAP          my_bitmap;
VOID            *ppvBits = NULL;
HDC              client_area_DC;
HDC              my_hdc;
DWORD           last_error = 3;

my_bit_map_info_header.biSize          = IMAGE_ROW_COUNT * IMAGE_COLUMN_COUNT * BYTES_PER_PIXEL;
my_bit_map_info_header.biWidth         = IMAGE_COLUMN_COUNT;
my_bit_map_info_header.biHeight        = IMAGE_ROW_COUNT;
my_bit_map_info_header.biPlanes        = 1;              // F1 help says must be 1.
my_bit_map_info_header.biBitCount      = RGB_THREE_BYTES_PER_PIXEL;
my_bit_map_info_header.biCompression   = BI_RGB;
my_bit_map_info_header.biSizeImage     = 0;     // per F1 help
                                                // but: [URL unfurl="true"]http://www.codeguru.com/forum/printthread.php?t=456626[/URL]
                                                // uses 256.
my_bit_map_info_header.biXPelsPerMeter = 0;     // Google found something that said always 0;
my_bit_map_info_header.biYPelsPerMeter = 0;
my_bit_map_info_header.biClrUsed       = 0;   // my guess
my_bit_map_info_header.biClrImportant  = 0;   // my guess

my_rgb_quad.rgbBlue     = 255;
my_rgb_quad.rgbGreen    = 255;
my_rgb_quad.rgbRed      = 255;
my_rgb_quad.rgbReserved = 0;

my_bit_map_info.bmiHeader    = my_bit_map_info_header;
my_bit_map_info.bmiColors[0] = my_rgb_quad;

client_area_DC = ::GetDC( NULL );
my_hdc =  CreateCompatibleDC( client_area_DC );

my_bitmap = CreateDIBSection( 
      my_hdc,                 // handle to DC
      &my_bit_map_info,       // bitmap data
      DIB_RGB_COLORS,         // data type indicator
      &ppvBits,               // Provide the address of a pointer so the function can
                              // return a bit map.  So says the documentation.
      NULL,                   // 
      0 );                    // zero.Goes with the previous NULL
last_error = GetLastError();


return nRetCode;

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
At the least, initialize biSize member by sizeof(BITMAPINFOHEADER).

 
That made a difference. Now my_bitmap and ppvBits both are no longer zeroes. I was thinking that was the size of the bit map I wanted.

I do find it curious that the size of the structure must be in there. There are no pointers, no arrays, nothing I can see that would ever change the size of the structure. The debugger shows 40 so it will always be 40. Oh well.

You have helped me make another step. Now I will go back and see what to do next. If you want to throw any more hints my way I am all ears.

Thanks for taking the time to post.

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
It's Windows API style to place the size of a structure into the 1st element. Probably it helps to recognize the structure object version.

Win API calculates the size of the bitmap automatically by another members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top