最近我注意到 bitblt 非常慢(一张图像大约需要 33 毫秒),我知道这并不是我的硬件太慢,因为它以大约 50 fps 的速度运行具有良好图形的游戏。那么,我可以使用哪些替代 bitblt 来实现相同的结果?
我正在运行 Windows XP
这是我正在使用的代码:
#include <windows.h>
#include <tgmath.h>
#include <stdio.h>
void rotatebmp (HDC hdc_x, float q, float x0, float y0)
{
q = (q * 0.01745333055);
XFORM blah;
blah.eM11 = cos(q);
blah.eM12 = sin(q);
blah.eM21 = -sin(q);
blah.eM22 = cos(q);
blah.eDx = x0 - cos(q)*x0 + sin(q)*y0;
blah.eDy = y0 - cos(q)*y0 - sin(q)*x0;
SetWorldTransform(hdc_x, &blah);
return;
}
int main()
{
float q = 0;
HDC hdc = CreateCompatibleDC(NULL);
HBITMAP cross = (HBITMAP)LoadImage(NULL, ("C:\\Documents and Settings\\Death\\My Documents\\45Hand.bmp") ,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HBITMAP crossmask = (HBITMAP)LoadImage(NULL, ("C:\\Documents and Settings\\Death\\My Documents\\45Hand2.bmp") ,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
timeBeginPeriod(1);
DWORD totalt = 0;
while (1)
{
DWORD startt = timeGetTime();
float tfactor = (totalt * 0.01);
tfactor = (3.6 * tfactor);
q = (q + tfactor);
HDC hdc_x = GetDC(HWND_DESKTOP);
SetGraphicsMode(hdc_x, GM_ADVANCED);
SelectObject(hdc, crossmask);
rotatebmp (hdc_x, q, 850, 375);
BitBlt(hdc_x,550,0,600,527,hdc,0,0, SRCAND);
ReleaseDC(HWND_DESKTOP,hdc_x);
hdc_x = GetDC(HWND_DESKTOP);
SetGraphicsMode(hdc_x, GM_ADVANCED);
SelectObject(hdc, cross);
rotatebmp (hdc_x, q, 850, 375);
BitBlt(hdc_x,550,0,600,527,hdc,0,0, SRCPAINT);
ReleaseDC(HWND_DESKTOP,hdc_x);
Sleep(10);
DWORD endt = timeGetTime();
totalt = (endt - startt);
}
timeEndPeriod(1);
return 0;
}