-
bitmap
Can someone please help?I'm trying to print a bitmap to the screen.
This is where I'm upto:
------------------------------------------------------------------------------------
void CSketcherView::OnDraw(CDC* pDC)
{
CSketcherDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CBitmap MyBit;
MyBit.LoadBitmap(IDB_BITMAP2);
MyBit.CreateBitmap(100,40,);
CBitmap* pOldBitmap = pDC->SelectObject(&MyBit);
pDC->BitBlt(0,0,100,100,pDC,0,0,SRCCOPY);
----------------------------------------------------------------------------------
I'm not sure of the last three parameters in CreateBitmap.
Also BitBlt could be wrong.
I have looked through the forum but still can't work it out.
Phil
-
Here is one solution.
Code:
CBitmap MyBit;
MyBit.LoadBitmap(IDB_BITMAP2);
MyBit.CreateBitmap(100,40,);
CDC memoryDC;
memoryDC.CreateCompatibleDC(pDC);
CBitMap *pOldBitmap = memoryDC.SelectObject(&MyBit);
memoryDC.SetMapMode(pDC->GetMapMode());
memoryDC.BitBlt(0, 0, 100, 100, &memoryDC, 0, 0, SRCCOPY);
memoryDC.SetObject(pOldBitMap);
The solution is you should create a memory device context, load the bitmap onto the virtual DC, and then blit it onto the screen.
Kuphryn
-
Thanks for helping me with my problem kuphryn.I still can't
get it to compile.Here are the errors.
---------------------------------------------------------------------------------
cpp(63) : error C2660: 'CreateBitmap' : function does not take 2 parameters
cpp(70) : error C2039: 'SetObject' : is not a member of 'CDC'
microsoft visual studio\vc98\mfc\include\afxwin.h(636) : see declaration of 'CDC'
I can see that the CreateBitmap function has more parameters.
I looked up in msdn but I'm still not sure of the values to put there.
Phil
-
:) Since my last post I found a tutorial on the web.Which I
tried and it worked first time.Great my first bitmap.
For anyone who is interested the link is
http://www.wiu.edu/users/mflll/CS412g/bitmaps.html
Phil
-
Cool.
I made some typos in the reply. One of which was "SetObject." I meant "SelectObject."
Kuphryn