vc 截取屏幕

来源:百度知道 编辑:UC知道 时间:2024/05/18 12:22:38
本人需要实现以下功能
1.截取屏幕
2.将截取到的屏幕图像保存为jpg

现在的程序可以实现上述的功能,但是实现的手法并不好,先将屏幕的图像放入CBitmap,然后保存为BMP,然后用CImage载入BMP再保存为JPG

有没有办法直接将截取的图像放入CImage中,或者有没有什么办法将CBitmap中的图像不经过硬盘直接被CImage保存为JPG,如果CBitmap能直接保存为JPG更好
to hnjdbxf:
保存成BMP我早已实现
to 卩过眼云烟灬:
扯淡
to constmy:
该方法试过,一用就异常

诸位不要胡说,看我的代码
这是直接用CImage截屏,不需要CBitmap,也不用保存为BMP再转换

BOOL bFull=true;//是否截全屏,false则只截取当前活动的窗体
CImage image;
CWnd* pWnd;
CRect rect;
BOOL bStat;
if(bFull)
pWnd = CWnd::GetDesktopWindow();
else
pWnd = CWnd::GetActiveWindow();

ASSERT(pWnd);
if(pWnd == NULL)
return FALSE;

CWindowDC winDC(pWnd);
pWnd->GetWindowRect(&rect);

int nBPP = winDC.GetDeviceCaps(BITSPIXEL) * winDC.GetDeviceCaps(PLANES);
if(nBPP < 24) nBPP = 24;

bStat = image.Create(rect.Width(), rect.Height(), nBPP);
ASSERT(bStat);
if(!bStat)
return FALSE;

CImageDC imageDC(image);

::BitBlt(imageDC, 0, 0, rect.Width(), rect.Height(), winDC, 0, 0, SRCCOPY);

SYSTEMTIME sys;
GetLocalTime(&sys);
m_StaticTime.Format("%4d%02d%02d%02d%02d%02d",sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute,sys.wSecond);