Re: save DC as bitmap to file
I tried your to use your code inside InPaint, but it fails:
void CGraphCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect (rc);
GetClientRect(rc);
//CMemDC pDC(&dc,&rc); // Double Buffering
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
Bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
CBitmap *pOldBitmap = MemDC.SelectObject(&Bmp);
COLORREF c;
if ((m_PixelNumberX>0) && (m_PixelNumberY > 0))
{
for (int ix=0; ix < m_PixelNumberX; ix++)
{
for (int iy=0; iy < m_PixelNumberY; iy++)
{
c=PlotData[ix][iy];
//pDC->SetPixel(ix,iy,c);
MemDC.SetPixel(ix,iy,c);
}
}
}
dc.BitBlt(0,0,rc.Width(),rc.Height(),&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBitmap);
}
The function is processed first completely then only up to
Bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
starts then again at the beginning and stops then at
CBitmap *pOldBitmap = MemDC.SelectObject(&Bmp);
inside
BOOL CGdiObject::Attach(HGDIOBJ hObject)
{
ASSERT(m_hObject == NULL); // only attach once, detach on
destroy
so, I do not know what is going wrong at this point.
Secondly, could you be so kind to explain where in this code the
bitmap is saved to Bmp ? I can only see information being passed to
MemDC.
Matthias