直接上程序:
void CTestDlg::DoIt()
{
// TODO: Add your control notification handler code here
LARGE_INTEGER litmp;
LONGLONG qt1,qt2;
double dft,dff,dfm;
//获得时钟频率
QueryPerformanceFrequency(&litmp);//获得时钟频率
dff=(double)litmp.QuadPart;
//获得初始值
QueryPerformanceCounter(&litmp);
qt1=litmp.QuadPart;
HDC hScrDC, hScreen;
HBITMAP hBitmap;
hScreen = ::CreateDC("DISPLAY", NULL, NULL, NULL);
hScrDC =::CreateCompatibleDC(hScreen);
int w = GetDeviceCaps(hScreen, HORZRES);
int h = GetDeviceCaps(hScreen, VERTRES);
hBitmap = CreateCompatibleBitmap(hScreen, w,h);
if (hBitmap == 0)
{
AfxMessageBox("hbmScreen");
}
if (!SelectObject(hScrDC, hBitmap))
{
AfxMessageBox("Compatible Bitmap Selection");
}
if (!BitBlt(hScrDC,0,0, w, h, hScreen, 0,0, SRCCOPY))
{
AfxMessageBox("BitBlt");
}
COLORREF rgb = 0;
for (int i=0; i<w; i++)
{
for (int j=0; j<h; j++)
{
rgb = ::GetPixel(hScrDC, i, j);
//int r = GetBValue(rgb);
int g = GetGValue(rgb);
//int b = GetRValue(rgb);
rgb = RGB(g, g, g);
::SetPixel(hScrDC, i, j, rgb);
}
}
if (!BitBlt(hScreen,0,0, w, h, hScrDC, 0,0, SRCCOPY))
{
AfxMessageBox("BitBlt");
}
//获得终止值
QueryPerformanceCounter(&litmp);
qt2=litmp.QuadPart;
//获得对应的时间值,转到毫秒单位上
dfm=(double)(qt2-qt1);
dft=dfm/dff;
CString str;
str.Format("修改完成,耗时: %.3f秒", dft);
SetWindowText(str);
DeleteObject(hBitmap);
DeleteDC(hScrDC);
DeleteDC(hScreen);
}
本文详细介绍了如何利用DirectX技术直接在屏幕上绘制并优化显示效果,包括初始化DirectX环境、创建设备上下文、创建位图、位图选择、位图位复制以及性能计时等关键步骤。通过实现屏幕像素的快速更新与颜色调整,显著提升视觉体验与响应速度。
&spm=1001.2101.3001.5002&articleId=43610537&d=1&t=3&u=15bfc47da476403e847e4fea463ff225)
666

被折叠的 条评论
为什么被折叠?



