
How can i create a device independent bitmap from a rgb buffe
Here is an answer two your question:
http://www.spbteam.com/pocketpc/qa/offscreen_buffer.html
Vassili Philippov
-------------------------------------------------------------------
How to implement offscreen buffer?
Question
I need to output function graphic. When I draw the graphic using GDI
function I see flicker. I want to create an offscreen buffer to prevent this
flicker. How can I do that?
Answer
You have to create a bitmap as a buffer. Then create memory device context
and select this bitmap into the device context. Then draw into this memory
context and then copy the memory device context into the target device
context using BitBlt function.
Or you can use STScreenBuffer library that encapsulates most of this work
and make implementation of a screen buffer simpler. More over
CSTScreenBuffer class gives you fast access to points that could not be done
using GDI functions.
Source code:
The following code gives example of an offscreen buffer using STScreenBuffer
library.
void CMyView::OnDraw(CDC* pDC)
{
CSTScreenBuffer sb;
sb.Create(pDC, CRect(0 , 0, 100, 80));
sb.GetDC()->Rectangle(10, 10, 20, 20);
sb.Draw(pDC, CPoint(0,0));
Quote:
}
The following code gives example of an offscreen buffer using
MFC functions.
void CMyView::OnDraw(CDC* pDC)
{
CDC memDc;
if (!memDc.CreateCompatibleDC(pDC)) {
return;
}
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, 100, 80);
HBITMAP m_hOldBitmap = (HBITMAP)::SelectObject(memDc.GetSafeHdc(),
bmp.GetSafeHandle());
memDc.BitBlt(0,0, 100, 80, pDC, 0, 0, SRCCOPY);
memDc.Rectangle(10, 10, 20,20);
pDC->BitBlt(0, 0, 100 ,80, &memDc, 0, 0, SRCCOPY);
::SelectObject(memDc.GetSafeHdc(), m_hOldBitmap);
memDc.DeleteDC();
Quote:
}