截屏并保存JPG图片

//获取截图数据

CDC *pDC;

pDC = CDC::FromHandle(::GetDC(GetDesktopWindow()->m_hWnd));

if(pDC == NULL) return;

int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);

 

CRect rcClient;

GetWindowRect(rcClient);

 

CDC memDC;

if(memDC.CreateCompatibleDC(pDC) == 0) return;

 

CBitmap memBitmap, *oldmemBitmap;

if(memBitmap.CreateCompatibleBitmap(pDC, rcClient.Width(), rcClient.Height()) == NULL) return;

 

oldmemBitmap = memDC.SelectObject(&memBitmap);

if(oldmemBitmap == NULL) return;

if(memDC.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), pDC, rcClient.left, rcClient.top, SRCCOPY) == 0) return;

 

CImage img;

img.Attach(memBitmap);

img.Save(strPath.c_str(), ImageFormatJPEG);  //也可以是其他格式,如Png....

 

memDC.SelectObject(oldmemBitmap);

你可能感兴趣的:(null)