C:截屏

时间:2010-07-30 10:42:36

标签: c windows screenshot

如何捕获屏幕并将其保存为C中的图像? OS:windows(XP& Seven)

由于

2 个答案:

答案 0 :(得分:3)

你试过google吗?这个forum entry有一个例子,使用Win32 API完成C源代码。

编辑:在此期间发现重复:How can I take a screenshot and save it as JPEG on Windows?

答案 1 :(得分:3)

如果您不想费心点击链接

#include <windows.h>

bool SaveBMPFile(char *filename, HBITMAP bitmap, HDC bitmapDC, int width, int height);

bool ScreenCapture(int x, int y, int width, int height, char *filename){
  // get a DC compat. w/ the screen
  HDC hDc = CreateCompatibleDC(0);

  // make a bmp in memory to store the capture in
  HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height);

  // join em up
  SelectObject(hDc, hBmp);

  // copy from the screen to my bitmap
  BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY);

  // save my bitmap
  bool ret = SaveBMPFile(filename, hBmp, hDc, width, height);

  // free the bitmap memory
  DeleteObject(hBmp);

  return ret;
}

main(){
  ScreenCapture(500, 200, 300, 300, "testScreenCap.bmp");
  system("pause");
}