470,858 Members | 1,928 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,858 developers. It's quick & easy.

Create Bitmap Draw on it and save it


Please tell me how to create a bitmap. Draw on it and how to save that bitmap to a bmp file.

I done following : on a button click event.

Expand|Select|Wrap|Line Numbers
  1.         CDC* pDC = GetDC();
  2.     CDC memDC;
  3.     CBitmap newbmp;
  4.     CImage img;    
  5.     CBrush brush;
  6.     brush.CreateSolidBrush(RGB(0, 0, 255));
  7.     pDC->SelectObject(&brush);
  8.     memDC.CreateCompatibleDC(pDC);
  9.     btmap.CreateCompatibleBitmap(&memDC, 300, 300);
  10.     pDC->Rectangle(10, 10, 80, 80);
  11.     pDC->Ellipse(60,60,220,220);
  12.     memDC.SelectObject(&newbmp);    
  13.     memDC.BitBlt(0,0,300,300,pDC,0,0,SRCCOPY);
  14.     CString loc("C:\\atest.bmp");
  15.     LPCTSTR bmp = (LPCTSTR)loc;
  16.     img.Attach(newbmp);
  17.     img.Save(bmp,Gdiplus::ImageFormatBMP);
  18.     ReleaseDC(pDC);
But all do just get the window details and save it. If there a window above that it will also draw that.

Every thing we draw with pDC come on the screen. Such that is there any way to draw to CDC of bitmap (similar to CDC pDC = GetDC();). And when we save it then only what we draw on that CDC should be saved, nothing more.

Please reply immediatly ..
Thanks in advance
Feb 25 '08 #1
1 5300
9,065 Expert Mod 8TB
Instead of pDC->Rectangle call memDC->Rectangle, but only after you have selected the bitmap into the memDC. Same for Eclipse. Don't call memDC.BitBlt.
Feb 26 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Programmer | last post: by
1 post views Thread by jay | last post: by
2 posts views Thread by John | last post: by
12 posts views Thread by Lee | last post: by
11 posts views Thread by Mark B | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.