Problem in attaching CBitmap to CImage's Attach()
-
i'm trying to attach CBitmap to CImage,but itz not working. /* CBitmap bmpCap; CBitmap *pBmpOld; CImage img; these three r declared in CChildView class */ //following code is in OnPaint() function...
CRect rect;
CDC dcMem;
dc.TextOutA(20,20,"Humais");
GetClientRect(&rect);
bmpCap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
pBmpOld=dc.SelectObject(&bmpCap);i'm getting runtime error...
-
i'm trying to attach CBitmap to CImage,but itz not working. /* CBitmap bmpCap; CBitmap *pBmpOld; CImage img; these three r declared in CChildView class */ //following code is in OnPaint() function...
CRect rect;
CDC dcMem;
dc.TextOutA(20,20,"Humais");
GetClientRect(&rect);
bmpCap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
pBmpOld=dc.SelectObject(&bmpCap);i'm getting runtime error...
-
I don't know what you are trying to do here, but to answer your question
img.Attach(bmpCap.Detach());
// do some painting with img
bmpCap.Attach(img.Detach());pBmpOld
should be a local variable. Probablyimg
as well. -
i'm drawing shapes on CPaintDC dc....then i want to attach those shapes to img...so i can save them... can u please tell me proper steps?
This would be close (using only local variables)
CRect rect;
GetClientRect(&rect);CBitmap bmpCap;
bmpCap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
CBitmap *pBmpOld = dc.SelectObject(&bmpCap);dc.TextOutA(20,20,"Humais");
dc.SelectObject(pBmpOld);
CImage img;
img.Attach(bmpCap.Detach());img.Save(...);
bmpCap.Attach(img.Detach());
...
-
This would be close (using only local variables)
CRect rect;
GetClientRect(&rect);CBitmap bmpCap;
bmpCap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
CBitmap *pBmpOld = dc.SelectObject(&bmpCap);dc.TextOutA(20,20,"Humais");
dc.SelectObject(pBmpOld);
CImage img;
img.Attach(bmpCap.Detach());img.Save(...);
bmpCap.Attach(img.Detach());
...
-
i'm using save function,thats why i declare CImage & CBitmap in CChildView class..tell me now where i have to put
img.Attach(bmpCap.Detach());
i mean in save function or in OnPaint function??
In save. You have the bitmap in bmpCap, so you only have to move the handle over to the CImage instance while saving, and then move it back again. Make sure you're not creating the bitmap every time you enter OnPaint (should that not be OnDraw btw?). Verify that
(HBITMAP)bmpCap == nullptr
before creating it.