• C

Saving a Windows Drawing as a Bitmap or Picture File

I am using Visual C++ 6.0 to make a drawing.
I wish to now save the whole drawing (whether it is all
visible or not) as a standard image file
(bitmap, JPG, GIF, whatever). I don't want to do it with
the Print Screen key, which would copy it into the ClipBoard, and only copy what you see.
I need to automatically save it as a separate file.
How can this be done ? Please provide detailed example.
Who is Participating?
AlexVirochovskyConnect With a Mentor Commented:
You can easy save you Screen as Bitmap:
1. Make hBitmap (left, top,right, bottom: saved Rect)
HDC hdc, mdc;
  HBITMAP hOld, hBitmap;
  int left, right, top, bottom;

  hdc = GetDC(NULL);
  iBits  = GetDeviceCaps(hdc,BITSPIXEL);
  hBitmap = CreateBitmap(right-left, bootom-top, 1, iBits, NULL);
  mdc = CreateCompatibleDC(hdc);
  hOld = (HBITMAP)SelectObject(mdc, hBitmap);
  BitBlt(mdc, left, top,right, bottom, hdc, 0, 0,SRCCOPY);    //clipping!
  SelectObject(mdc, hOld);
  ReleaseDC (NULL, hdc);
2. Save hBitmap as file see


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.