Naveen
Naveen

Reputation: 73503

Parameters to be passed to the CreateDIBSection function

I have a color image with number of rows 479 and columns 638. I am trying to save this image as a BMP file. For this I am first using CreateDIBSection and then using CreateDIBitmap. For the CreateDIBSection I need to pass the BITMAPINFOHEADER to the function. Here it has two parameters biWidth and biSizeImage. Since the memory returned by the function should be DWORD aligned, and 638 is not a multiple of 4 should I pass 638 or 640 as the width ? Assume that I pass 638 as the width, will the memory returned by the function be 638 x 479 or 640 x 479 ? My observation is that it is the 640 x 479. In this case when I save the file as a BMP a 2 pixel wide black line appears at the end of each row. How do I avoid this? I am passing biCompression as BI_RGB if that matters.

Upvotes: 0

Views: 400

Answers (1)

Deanna
Deanna

Reputation: 24303

You should pass the actual width as the bitmap width. The scanline/stride however has to be dword aligned. This just means adding up to 3 bytes to each line when calculating the stride and memory buffer size.

Note that the actual width of the data depends on the bits per pixel. If you;re using 32-bit pixels then it's already aligned correctly.

Upvotes: 1

Related Questions