Jump to content
  • Advertisement
Sign in to follow this  

Loading Bitmap Article

This topic is 5224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In this article I don't understand one part where the author deals with padding
DWORD diff;
int offset;
LONG height;

//set diff to the actual image size(no padding)
//allocate memory for the image
pixelData=new BYTE[diff];
if(pixelData==NULL) {
    return false;
//bitmap is inverted, so the padding needs to be removed
//and the image reversed
//Here you can start from the back of the file or the front,
//after the header.  The only problem is that some programs
//will pad not only the data, but also the file size to
//be divisible by 4 bytes.
if(height>0) {
    int j==size-3;
    for(int i=0;i<size;i+=3) {
        if((i+1)%padWidth==0) {
//the image is not reversed.  Only the padding needs to be removed.
else {
    do {
    } while(offset<height);

I don't get how this part if((i+1)%padWidth==0) { i+=offset; } is supposed to take care of the padding in the pixel data

Share this post

Link to post
Share on other sites
Hi Snisarenko,
Scan lines in windows bitmaps must be padded to finish on a LONG boundary.
from the Windows SDK:

A device-independent bitmap consists of two distinct parts: a BITMAPINFO structure describing the dimensions and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in the array are packed together, but each scan line must be padded with zeroes to end on a LONG boundary. If the height is positive, the origin of the bitmap is the lower-left corner. If the height is negative, the origin is the upper-left corner.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!