I have written some code to draw some lines etc in a device context and bitmap in ondraw class.
I can save that bitmap using cimage but I want to access that bitmap from other button or class.
The bitmap is not accessible from anywhere other than the ondraw class. I have also tried taking the bitmap as global variable but no use.
Can any body please show some method to copy the bitmap or how to use it in other class or function and another approach would also be help full if anyone can show how to get the window image to a bitmap then I will have the window where I have drawn the lines etc to a bitmap.
Here is the code:
CClientDC dcScreen (this);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap (&dcScreen, 500, 500);
CDC dcMem;
dcMem.CreateCompatibleDC (&dcScreen);
CBrush brush (RGB (255, 255, 255));
CBitmap* pOldBitmap = dcMem.SelectObject (&bitmap);
dcMem.FillRect (CRect (0, 0, 500, 500), &brush);
dcMem.MoveTo(50,50); dcMem.LineTo(50,200); dcMem.LineTo(150,200); dcMem.LineTo(150,50); dcMem.LineTo(50,50);
dcScreen.BitBlt (0, 0, 500, 500, &dcMem, 0, 0, SRCCOPY);
dcMem.SelectObject (pOldBitmap);
CImage img;
img.Attach(bitmap);
img.Save(L"atest.jpg",Gdiplus::ImageFormatJPEG);