问题
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