1

我正在开发一个 GIF 程序。基本上我有我需要的一切并且程序正在运行,但问题是显示的帧比它应该的慢一点(例如,与浏览器中的 GIF 动画相比,尽管我将计时器设置为正确的时间)。我的程序的重要摘录:

// converting the frames to DDBs to perform the fastest BitBlt
for(int i=0;i<gifImage->getFramesQuantity();i++)
{
    frames_bitmaps[i]=(HBITMAP)CreateDIBitmap(GetDC(hwnd),
                      &(gifImage->getFrame(i)->bmpInfoHeader),
                      CBM_INIT,gifImage->getFrame(i)->bmpImgData,
                      gifImage->getFrame(i)->bmpInfo2,DIB_RGB_COLORS);
}

// setting timeBeginPeriod to ensure receiving WM_TIMER in the exact time
timeBeginPeriod(1)

void GIFWindow::onDCChange()
{
    ReleaseDC(hwnd,hdc);
    DeleteDC(hdcMem);

    hdc=GetDC(hwnd);
    hdcMem=CreateCompatibleDC(hdc); 
}

// frame drawing function
void GIFWindow::drawFrame()
{
    SelectObject(hdcMem,frames_bitmaps[current_bitmap]);
    BitBlt(hdc,image_x,image_y,gifImage->getWidth(),gifImage->getHeight(),hdcMem,0,0,SRCCOPY);
}

void GIFWindow::startAnimation()
{ 
    drawFrame();
                                                                 // returns the delay in ms
    SetTimer( hwnd, TIMER_ID, gifImage->getFrame(current_bitmap)->getDelay(), NULL );
}

void GIFWindow::onTimer(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    KillTimer( hwnd, TIMER_ID);

    if(current_bitmap==gifImage->getFramesQuantity()-1)
        current_bitmap=0;
    else
        current_bitmap++;

    drawFrame();

    SetTimer( hwnd, TIMER_ID, gifImage->getFrame(current_bitmap)->getDelay(), NULL );
}

我将不胜感激有关我的代码和想法的任何评论如何提高性能

4

0 回答 0