19,472
社区成员




for (int i = 0; i+3 < bitmap.bmWidth * bitmap.bmHeight * 3; i+=3)
{
row_tmp2[i] = row_tmp[i+3];
row_tmp2[i+2] = row_tmp[i+2];
row_tmp2[i+3] = row_tmp[i];
}
memcpy(Bits, row_tmp2, bitmap.bmWidth * bitmap.bmHeight * 3);
for (int i = 0; i+3 < bitmap.bmWidth * bitmap.bmHeight * 3; i+=3)
{
// row_tmp2[i] = row_tmp[i+3];
// row_tmp2[i+2] = row_tmp[i+2];
// row_tmp2[i+3] = row_tmp[i];
// BITMAP是倒着来的,从下往上写
row_tmp2[i] = row_tmp[bitmap.bmWidth * bitmap.bmHeight * 3];
}
注意看这里的
// row_tmp2[i] = row_tmp[i+3];
// row_tmp2[i+2] = row_tmp[i+2];
// row_tmp2[i+3] = row_tmp[i];
修改成:
for (int i = 0; i+3 < bitmap.bmWidth * bitmap.bmHeight * 3; i+=3)
{
row_tmp2[i] = row_tmp[i+2];
row_tmp2[i+1] = row_tmp[i+1];
row_tmp2[i+2] = row_tmp[i];
}
看看效果for (int i = 0; i+3 < bitmap.bmWidth * bitmap.bmHeight * 3; i+=3)
{
row_tmp2[i] = row_tmp[i+3];
row_tmp2[i+2] = row_tmp[i+2];
row_tmp2[i+3] = row_tmp[i];
}
为什么不是i+1,i+2...
bytes_per_line = ((width * 3 + 3) / 4) * 4;
bytes_per_pixel = depth / 8;
Header.Info.biSize = sizeof(BITMAPINFOHEADER);
Header.Info.biWidth = width;
Header.Info.biHeight = height;
Header.Info.biBitCount = depth;
Header.Info.biPlanes = 1;
Header.Info.biXPelsPerMeter = 0;
Header.Info.biYPelsPerMeter = 0;
Header.Info.biClrUsed = 0;
Header.Info.biClrImportant = 0;
Header.Info.biCompression = depth == 24? BI_RGB: BI_BITFIELDS; //24位要设定BI_RGB,其它16位或32位设定为BI_BITFIELDS
Header.Info.biSizeImage = bytes_per_line * height;
for (int i = 0; i+3 < bitmap.bmWidth * bitmap.bmHeight * 3; i+=3)
{
// row_tmp2[i] = row_tmp[i+3];
// row_tmp2[i+2] = row_tmp[i+2];
// row_tmp2[i+3] = row_tmp[i];
// BITMAP是倒着来的,从下往上写
row_tmp2[i] = row_tmp[bitmap.bmWidth * bitmap.bmHeight * 3];
}