我将一幅图像显示出来,但是不知道怎样才能将鼠标点击的图像上的坐标点转换为图像上像素点的位置坐标
请大家帮一下忙。。

解决方案 »

  1.   

    你显示到哪?如果是显示到指定窗口上,可以在窗口的鼠标消息里取出坐标。或者GetCursorPos取出鼠标指针的坐标,然后通过ScreenToClient、MapWindowPoints等函数转换为窗口坐标
      

  2.   


    BOOL ScreenToClient(
      HWND hWnd,        // handle to window
      LPPOINT lpPoint   // screen coordinates
    );
    Parameters
    hWnd 
    [in] Handle to the window whose client area will be used for the conversion. 
    lpPoint 
    [in] Pointer to a POINT structure that specifies the screen coordinates to be converted. 
    Return Values
    If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. 
      

  3.   

    根据图像在窗口区域的位置(矩形坐标)来换算。GetCursorPos取得的是窗口坐标位置,和图像的任意顶点(比如左下角的顶点)在窗口中的坐标位置比较。