本文介绍了CopyFromScreen()问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将桌面的CopyFromScreen图片设置为Image(或Bitmap)对象?
谢谢
How can I set the CopyFromScreen picture of desktop to Image (or Bitmap) object?
Thanks
推荐答案
HDC hdc = GetDC(0);
HDC mdc = CreateCompatibleDC(hdc);
HBITMAP hbmpscreen;
BITMAPINFO bmi;
HGDIOBJ obmp;
bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
bmi.bmiHeader.biWidth = GetSystemMetrics(SM_CXSCREEN);
bmi.bmiHeader.biHeight = GetSystemMetrics(SM_CYSCREEN);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = 0;
bmi.bmiHeader.biSizeImage = (((bmi.bmiHeader.biWidth*bmi.bmiHeader.biBitCount/8)+3)&~3)*bmi.bmiHeader.biWidth;
bmi.bmiHeader.biXPelsPerMeter = 300;
bmi.bmiHeader.biYPelsPerMeter = 300;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
hbmpscreen = CreateDIBitmap(mdc,&hbmpscreen,0,0,&bmi.bmiHeader,DIB_RGB_COLORS);
obmp = SelectObject(mdc,hbmpscreen);
BitBlt(mdc,0,0,bmi.bmiHeader.biWidth,bmi.bmiHeader.biHeight,hdc,0,0,SRCCOPY);
SelectObject(mdc,obmp);
DeleteDC(mdc);
ReleaseDC(hdc);
这篇关于CopyFromScreen()问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!