不需要CxImage这样的第三方扩展库
微软的GDI+也可以转换的
CImage mmage;
HWND hWnd = ::GetDesktopWindow();//获得屏幕的HWND.
HDC hScreenDC = ::GetDC(hWnd); //获得屏幕的HDC.
HDC MemDC = ::CreateCompatibleDC(hScreenDC);
RECT rect;
::GetWindowRect(hWnd,&rect);
HBITMAP hBitmap = ::CreateCompatibleBitmap(hScreenDC,rect.right,rect.bottom);
HGDIOBJ hOldBMP = ::SelectObject(MemDC,hBitmap);
::BitBlt(MemDC,0,0,rect.right,rect.bottom,hScreenDC,rect.left,rect.top,SRCCOPY);
hBitmap=(HBITMAP)::SelectObject(MemDC,hOldBMP);
mmage.Attach(hBitmap);
IStream* pStmImage = NULL;
HGLOBAL hMemBmp = GlobalAlloc(GMEM_MOVEABLE,0);//可移动的缓冲区
if (hMemBmp == NULL) return 0;
CreateStreamOnHGlobal(hMemBmp, FALSE, &pStmImage);//将内存区B作为流的起始
if (pStmImage == NULL)
{
GlobalFree(hMemBmp);
AfxMessageBox("为空");
return 0;
}
mmage.Save(pStmImage,Gdiplus::ImageFormatJPEG);