Picture control coordinate transformation in MFC

Source: Internet
Author: User

OPENCV in the MFC framework, it is unavoidable to use the picture control to display pictures, but the picture control displays the image's basic unit is the screen coordinate system, if you need to get a pixel coordinate system, only one simple step to convert. Of course, if it is opencv2.0 and above, you need to use cvvimage this class, online can be downloaded to.

The core idea of coordinate transformation is to make a simple conversion according to the ratio between the size of the client area of the picture space and the actual size of the image that needs to be displayed, the code is as follows:

1     /*get customer Area coordinates2     */3 CRect rect_ctr; 4(GetDlgItem (Idc_imgshow))->getwindowrect (&rect_ctr);5 screentoclient (RECT_CTR); 6Point.x = Point.x-Rect_ctr.left; 7Point.y = Point.y-Rect_ctr.top; 8 9     /*Convert screen coordinates to pixel coordinatesTen * Point.x and POINT.Y the client area screen coordinates for the current mouse One * m_icoordinate_pixel_x, such as converted pixel coordinates, the use of image and customer area coordinate relationship transformation A     */ -m_icoordinate_pixel_x = Point.x * M_iimage_width/(Rect_ctr.right-rect_ctr.left); -m_icoordinate_pixel_y = Point.y * M_iimage_height/(rect_ctr.bottom-rect_ctr.top);

Where Idc_imgshow is the picture control's id,m_iimage_width and m_iimage_height are two shaping variables, representing the original width and height (that is, the number of columns and rows) of the image to be displayed.

  

Picture control coordinate transformation in MFC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.