19,472
社区成员




int ret = 0;
//b包含图像信息和数据
int nColumn = b.getSizeX();
int nRow = b.getSizeY();
int nSize = b.getSize();
BITMAPINFOHEADER bi;
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = nColumn;
bi.biHeight = nRow;
bi.biPlanes = 1;
bi.biBitCount = 8;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
BITMAPINFO* pbi = (BITMAPINFO*)new BYTE[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
pbi->bmiHeader = bi;
// 初始化成员
for (int i=0;i<256;i++)
{
pbi->bmiColors[i].rgbBlue = i;
pbi->bmiColors[i].rgbGreen = i;
pbi->bmiColors[i].rgbRed = i;
pbi->bmiColors[i].rgbReserved = 0;
}
HDC hdc = m_Picture.GetDC()->GetSafeHdc();
char *pixel = (char *)b.getBuffer();
//正常
for(int j = 0; j < nRow; j++)
for (int i = 0; i < nColumn; i++)
{
BYTE p = pixel[j * nColumn + i];
COLORREF color = RGB(p, p, p);
::SetPixel(hdc,i,j,color);
}
//倾斜
SetStretchBltMode(hdc, COLORONCOLOR);
ret = ::StretchDIBits(hdc,
rect.left, rect.top, nColumn, nRow,
0, 0, nColumn, nRow,
b.getBuffer(), pbi, DIB_RGB_COLORS, SRCCOPY);