打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VC 实现快速截屏

// 截取全屏

#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;

}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Screen Capture and Save as an Image
C# 截取电脑屏幕
GDI 编程小结
GDI+的基本操作
从richeditctrl中按“\n”换行显示
如何使用GDI或者GDI+的函数对IplImage进行图像处理?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服