鍍金池/ 問(wèn)答/C  C++  網(wǎng)絡(luò)安全/ 關(guān)于使用使 GDI+ 圖形庫(kù)獲取屏幕截圖的問(wèn)題

關(guān)于使用使 GDI+ 圖形庫(kù)獲取屏幕截圖的問(wèn)題

我的代碼如下

#include "stdafx.h"
#include <iostream>
#include <atlimage.h>

using namespace std;

int main()
{
  int width = 1920;
  int height = 1080;
  int x_pos = 0, y_pos = 0;
  CImage image;

  HDC hdc_window = GetDC(NULL);
  int device_caps = GetDeviceCaps(hdc_window, BITSPIXEL);

  image.Create(width, height, device_caps);

  BitBlt(
    image.GetDC(),
    x_pos, y_pos,
    width, height,
    hdc_window,
    0, 0,
    SRCCOPY
  );

  ReleaseDC(NULL, hdc_window);
  image.ReleaseDC();

  image.Save(_T("c:\\test.bmp"), Gdiplus::ImageFormatBMP);

  cout << "保存成功: c:\\test.bmp" << endl;

  system("pause");
  return 0;
}

運(yùn)行好像也沒(méi)有報(bào)錯(cuò),但是也沒(méi)有生成文件,我是參考這篇文章做的https://lellansin.wordpress.c...

謝謝!

回答
編輯回答
逗婦惱

可能是沒(méi)有權(quán)限,用管理員運(yùn)行試試?或者把目錄改到其他地方,比如用戶(hù)文件夾或者桌面。

2017年10月17日 06:58