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