1

我有一些 OpenCV 项目,可以在静态控件上查看图像并具有放大/缩小功能。这是我得到的:

void UpdateImage(HWND hwnd, int zoom) {
if(img) {
    RECT rc;
    HWND hStatic = GetDlgItem(hwnd, IDC_IMG);
    HDC imgdc = GetDC(hStatic);
    GetClientRect(hStatic, &rc);
    HDC hdcMem = CreateCompatibleDC(imgdc);
    HBITMAP hbmMem = CreateCompatibleBitmap(imgdc, rc.right-rc.left, rc.bottom-rc.top);
    HGDIOBJ hbmOld = SelectObject(hdcMem, hbmMem);
    HBRUSH hbrBkGnd = GetSysColorBrush(COLOR_3DFACE);
    FillRect(hdcMem, &rc, hbrBkGnd);
    DeleteObject(hbrBkGnd);
    SetBkMode(hdcMem, TRANSPARENT);
    int wnow = zoom * img->width / 100;
    int hnow = zoom * img->height / 100;
    IplImage* temp = cvCreateImage(cvSize(wnow, hnow), img->depth, img->nChannels);
    if(wnow > img->width && hnow > img->height) {
        cvResize(img, temp, CV_INTER_LINEAR);
    } else {
        cvResize(img, temp, CV_INTER_AREA);
    }
    if(temp->width < rc.right && temp->height < rc.bottom) {
        ShowImage(temp, hdcMem, 0, 0, wnow, hnow, 0, 0);
    } else {
        ShowImage(temp, hdcMem, 0, 0, rc.right, rc.bottom, 0, 0);
    }
    BitBlt(imgdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdcMem, 0, 0, SRCCOPY);
    SelectObject(hdcMem, hbmOld);
    DeleteObject(hbmMem);
    DeleteDC(hdcMem);
    ReleaseDC(hStatic, imgdc);
    cvReleaseImage(&temp);
}
}

ShowImage()这个链接得到了这个功能。问题是当我通过缩放滑块更新图像时,静态控件闪烁。如何获得无闪烁功能?

提前致谢!

4

0 回答 0