// 截取全屏
#include
#include <GdiPlus.h>
#include <atlimage.h> // CImage
#pragma comment(lib, ’GdiPlus.lib’)
int main()
{
HDC hdcSrc = GetDC(NULL);
int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL);
int nWidth = GetDeviceCaps(hdcSrc, HORZRES);
int nHeight = GetDeviceCaps(hdcSrc, VERTRES);
CImage image;
image.Create(nWidth, nHeight, nBitPerPixel);
BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY);
ReleaseDC(NULL, hdcSrc);
image.ReleaseDC();
image.Save(L’ScreenShot.png’, Gdiplus::ImageFormatPNG);//ImageFormatJPEG
image.Save(L’ScreenShot.jpg’, Gdiplus::ImageFormatJPEG);//ImageFormatJPEG
image.Save(L’ScreenShot.bmp’, Gdiplus::ImageFormatBMP);//ImageFormatBMP
system(’pause’);
return 0;
}
#include
#include <GdiPlus.h>
#include <atlimage.h> // CImage
#pragma comment(lib, ’GdiPlus.lib’)
int main()
{
HDC hdcSrc = GetDC(NULL);
int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL);
int nWidth = GetDeviceCaps(hdcSrc, HORZRES);
int nHeight = GetDeviceCaps(hdcSrc, VERTRES);
CImage image;
image.Create(nWidth, nHeight, nBitPerPixel);
BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY);
ReleaseDC(NULL, hdcSrc);
image.ReleaseDC();
image.Save(L’ScreenShot.png’, Gdiplus::ImageFormatPNG);//ImageFormatJPEG
image.Save(L’ScreenShot.jpg’, Gdiplus::ImageFormatJPEG);//ImageFormatJPEG
image.Save(L’ScreenShot.bmp’, Gdiplus::ImageFormatBMP);//ImageFormatBMP
system(’pause’);
return 0;
}
// 截取部分
#include
#include <GdiPlus.h>
#include <atlimage.h> // CImage
#pragma comment(lib, ’GdiPlus.lib’)
struct Rect
{
int x;
int y;
int width;
int height;
Rect(int _x, int _y, int _w, int _h)
: x(_x), y(_y), width(_w), height(_h) {}
};
int main()
{
HDC hdcSrc = GetDC(NULL);
int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL);
int nWidth = GetDeviceCaps(hdcSrc, HORZRES);
int nHeight = GetDeviceCaps(hdcSrc, VERTRES);
Rect rect(100, 100, 800, 600);
CImage image;
image.Create(rect.width, rect.height, nBitPerPixel);
/*!
BOOL BitBlt(HDC hdc, int x, int y, int cx, int cy, HDC hdcSrc, int x1, int y1, DWORD rop);
hdc : 目标hdc
x : 目标矩形左上角的逻辑x坐标
y : 目标矩形左上角的逻辑y坐标
cx : 源矩形和目标矩形的宽度
cy : 源矩形和目标矩形的高度
hdcSrc : 源设备上下文句柄
x1 : 源矩形左上角的x坐标(以逻辑单位表示)。
x2 : 源矩形左上角的y坐标(以逻辑单位表示)。
rop :
*/
BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, rect.x, rect.y, SRCCOPY);
ReleaseDC(NULL, hdcSrc);
image.ReleaseDC();
image.Save(L’ScreenShot.png’, Gdiplus::ImageFormatPNG);//ImageFormatJPEG
image.Save(L’ScreenShot.jpg’, Gdiplus::ImageFormatJPEG);//ImageFormatJPEG
image.Save(L’ScreenShot.bmp’, Gdiplus::ImageFormatBMP);//ImageFormatBMP
//system(’pause’);
return 0;
}
#include
#include <GdiPlus.h>
#include <atlimage.h> // CImage
#pragma comment(lib, ’GdiPlus.lib’)
struct Rect
{
int x;
int y;
int width;
int height;
Rect(int _x, int _y, int _w, int _h)
: x(_x), y(_y), width(_w), height(_h) {}
};
int main()
{
HDC hdcSrc = GetDC(NULL);
int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL);
int nWidth = GetDeviceCaps(hdcSrc, HORZRES);
int nHeight = GetDeviceCaps(hdcSrc, VERTRES);
Rect rect(100, 100, 800, 600);
CImage image;
image.Create(rect.width, rect.height, nBitPerPixel);
/*!
BOOL BitBlt(HDC hdc, int x, int y, int cx, int cy, HDC hdcSrc, int x1, int y1, DWORD rop);
hdc : 目标hdc
x : 目标矩形左上角的逻辑x坐标
y : 目标矩形左上角的逻辑y坐标
cx : 源矩形和目标矩形的宽度
cy : 源矩形和目标矩形的高度
hdcSrc : 源设备上下文句柄
x1 : 源矩形左上角的x坐标(以逻辑单位表示)。
x2 : 源矩形左上角的y坐标(以逻辑单位表示)。
rop :
*/
BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, rect.x, rect.y, SRCCOPY);
ReleaseDC(NULL, hdcSrc);
image.ReleaseDC();
image.Save(L’ScreenShot.png’, Gdiplus::ImageFormatPNG);//ImageFormatJPEG
image.Save(L’ScreenShot.jpg’, Gdiplus::ImageFormatJPEG);//ImageFormatJPEG
image.Save(L’ScreenShot.bmp’, Gdiplus::ImageFormatBMP);//ImageFormatBMP
//system(’pause’);
return 0;
}
联系客服