#### Archived

This topic is now archived and is closed to further replies.

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

## Recommended Posts

I recently wrote my bitmap loader for my Direct X library, and I am running into an odd problem. The first version of the function worked perfectly, but I was only testing it on 320x240, 640x80 and such size bitmaps. Well, a problem arose when I started to load images that we un-even. Ex: 475x372 I would get either weird pixels in the colors Red,Green,Blue or I would get a black/colored line across the surface I loaded the bitmap too. So, I messaged a friend, and he told me he had the same problem. He told me that bitmaps are padded to end on perfect 32bit boundries. So, I said thanks and re-wrote my function. I fixed the problem: My code (I took out all the file loading crap and whatnot):
  //+--------------------------------------------------------------------------------------+ //| Now we are ready to pull data for the bitmap file. // Start pulling data from the file for( int nBmpScalarY = 0; nBmpScalarY < nBitmapWidth; nBmpScalarY++ ) { // Now grab the data and place it across the top of the surface for( int nBmpScalarX = 0; nBmpScalarX < nBitmapWidth; nBmpScalarX++ ) { // Note: Bmp''s are in BGR order, so we must pull in that order // Pull the blue component fBmpFile.read( (char*) &bBlue, sizeof( BYTE ) ); // Pull the green component fBmpFile.read( (char*) &bGreen, sizeof( BYTE ) ); // Pull the read component fBmpFile.read( (char*) &bRed, sizeof( BYTE ) ); // Compile the color uiRGB_Value = (bBlue) + (bGreen << 8) + (bRed << 16); // Set the color to the surface mem puiSurfMem[ uiPitchOffset + nBmpScalarX ] = uiRGB_Value; // seek forward in the file based on our padding fBmpFile.seekg( ( nBitmapWidth % sizeof(unsigned int) ), ios::cur ); } // Increment the offset uiPitchOffset += uiSurfPitch; } //| //+--------------------------------------------------------------------------------------+ 
So as a solution I seek forward in the file by the remainder of the width divided by the sizeof(unsigned int). It works for images like 475x372, but not for 374x372. I''ll keeping hacking away at it, but anyone got any ideas?

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999986
×