If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Problem with line alignment for Bitmap data

Hello,

I have already searched on the Internet about how to align each line of the bitmap data, so that it is displayed correctly. The lines must be a multiple of 4 Byte. I also tried to do so, however the problem still exists. As long as the image width is a multiple of 4 Byte, then it is displayed correctly otherwise, the lines are shifted against each other, so that the image is displayed corruptly ( see the attached files).

my steps to display the image are:

1) Load the image from the .bmp file

2) get its bits

3) Create and modify the BITMAPINFO struct, in order to pass it to SetStretchBltMode

Re: Problem with line alignment for Bitmap data

Thanks for your reply.

Unfortunately, it does not solve my problem because both padding algorithms are correct. It does not matter, whether I use your suggested algorithm or mine, the results are the same, for the image width of 251 pixels for example. The row stride without padding would be 251*3 = 753 Bytes and with padding 756 bytes.

That means the padding calculation is correct anyway. The question is: where should I use the padded row. May be the getting of raw bits from .bmp file is the weak point in my code. I tried to use GetDIBits() instead of using CBitmap Class and its members, but it returns me always an error. I guess some of the passed parameters are not correct.

Re: Problem with line alignment for Bitmap data

Problem solved!
For your interest, the problem was caused by the kind of how getting the image data from file.
I use the GetDIBits() function now and there are no problems for displaying images that have widths not multiple of 4 Byte.
Here is the code:

Re: Problem with line alignment for Bitmap data

If one line of the bitmap is not aligned, you may re-package them with 1-3 bytes added to each line. However, they may be a straight line with black or white color exists. I'm sure you may find some tips from the related open sources http://www.becoding.com/source/bitmap+alignment/ .