我要显示一灰度位图,但一做缩放就会灰度显示不正确。代码如下:void CTryView::OnMENUOpen()
{
.... m_bmpDC = new CDC();
m_bmpDC->CreateCompatibleDC(NULL);
m_bmp.CreateCompatibleBitmap(GetDC(), bmpinfo.biWidth, bmpinfo.biHeight);
m_bmpDC->SelectObject(&m_bmp); buffershow = new byte [bmpinfo.biHeight*bmpinfo.biWidth*4];
for(int i = 0; i<bmpinfo.biHeight*bmpinfo.biWidth; i++)
{
buffershow[i*4+0] = buffer[i];
buffershow[i*4+1] = buffer[i];
buffershow[i*4+2] = buffer[i];
buffershow[i*4+3] = 1;
}
delete [] buffer;
OnDraw(GetDC());
....
}void CTryView::OnDraw(CDC* pDC)
{
CTryshowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
...
m_bmp.SetBitmapBits(bmpinfo.biWidth*bmpinfo.biHeight*4, buffershow);
pDC->StretchBlt(0, 0, bmpinfo.biWidth/2, bmpinfo.biHeight/2, m_bmpDC, 0, 0,bmpinfo.biWidth, bmpinfo.biHeight, SRCCOPY);
}
请指教.
{
.... m_bmpDC = new CDC();
m_bmpDC->CreateCompatibleDC(NULL);
m_bmp.CreateCompatibleBitmap(GetDC(), bmpinfo.biWidth, bmpinfo.biHeight);
m_bmpDC->SelectObject(&m_bmp); buffershow = new byte [bmpinfo.biHeight*bmpinfo.biWidth*4];
for(int i = 0; i<bmpinfo.biHeight*bmpinfo.biWidth; i++)
{
buffershow[i*4+0] = buffer[i];
buffershow[i*4+1] = buffer[i];
buffershow[i*4+2] = buffer[i];
buffershow[i*4+3] = 1;
}
delete [] buffer;
OnDraw(GetDC());
....
}void CTryView::OnDraw(CDC* pDC)
{
CTryshowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
...
m_bmp.SetBitmapBits(bmpinfo.biWidth*bmpinfo.biHeight*4, buffershow);
pDC->StretchBlt(0, 0, bmpinfo.biWidth/2, bmpinfo.biHeight/2, m_bmpDC, 0, 0,bmpinfo.biWidth, bmpinfo.biHeight, SRCCOPY);
}
请指教.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货