Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
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);        // Set the current position
   dcMem.LineTo(50,200);       // Draw a vertical line down 150 units
   dcMem.LineTo(150,200);      // Draw a horizontal line right 100 units
   dcMem.LineTo(150,50);       // Draw a vertical line up 150 units
   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);
Posted
Updated 26-Mar-11 20:33pm
v2
Comments
Sandeep Mewara 27-Mar-11 2:33am    
Use PRE tags to format code part. It makes the question readable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900