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

## Recommended Posts

DWORD diff;
int offset;
LONG height;

height=bmih.biHeight;
//set diff to the actual image size(no padding)
diff=height*byteWidth;
//allocate memory for the image
pixelData=new BYTE[diff];
if(pixelData==NULL) {
fclose(in);
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) {
i+=offset;
}
*(pixelData+j+2)=*(tempPixelData+i);
*(pixelData+j+1)=*(tempPixelData+i+1);
*(pixelData+j)=*(tempPixelData+i+2);
j++;
}
}
//the image is not reversed.  Only the padding needs to be removed.
else {
height=height*-1;
offset=0;
do {
memcpy((pixelData+(offset*byteWidth)),
byteWidth);
offset++;
} 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 on other sites
Hi Snisarenko,
Scan lines in windows bitmaps must be padded to finish on a LONG boundary.
from the Windows SDK:
Quote:
 RemarksA 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.

HTH,
Cambo_frog

• 20
• 10
• 19
• 14
• 20