没有缓慢的任何比特替代方案吗?

时间:2013-06-28 12:44:49

标签: c++ windows graphics 2d bitblt

最近我注意到bitblt非常缓慢(1张图片大约需要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;
}

0 个答案:

没有答案