Zoom with OpenCV win32 C++

懵懂的女人 提交于 2019-12-08 06:46:21

问题


I have some OpenCV project that view image on static control and has zoom in / out functionality. Here what I got :

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);
}
}

I got the function ShowImage() from this link. The problem is that the static control was flickering when I update the image through zoom slider. How can I get flicker-free function?

Thanks in advance!

来源:https://stackoverflow.com/questions/15617635/zoom-with-opencv-win32-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!