Available in the LEADTOOLS Imaging toolkit. |
Pixel example for C++ 4.0 and later
This example, using the MouseDown event, gets the value of the current pixel and sets all values in the line to that value. The example shows how to convert mouse coordinates to bitmap pixel coordinates, regardless of how the image is zoomed or scrolled.
void CMfc2Dlg::OnMouseDownLead1(short Button, short Shift, long x, long y)
{
long xycolor;
float xfraction;
float yfraction;
float xPixel;
float yPixel;
// In MFC 4.0 you get pixels; so set the scalemode accordingly.
m_Lead1.SetScaleMode(3);
m_Lead1.SetAutoRepaint(FALSE);
// Translate mouse coordinates to fractions of the destination width and height.
xfraction = (x - m_Lead1.GetDstLeft()) / m_Lead1.GetDstWidth();
yfraction = (y - m_Lead1.GetDstTop()) / m_Lead1.GetDstHeight();
// Convert fractions to bitmap pixel coordinates.
xPixel = (m_Lead1.GetSrcWidth() * xfraction) + m_Lead1.GetSrcLeft();
yPixel = (m_Lead1.GetSrcHeight() * yfraction) + m_Lead1.GetSrcTop();
// Make the whole line the same color as the pixel.
xycolor = m_Lead1.GetPixel(xPixel, yPixel);
for(xPixel=0; xPixel<m_Lead1.GetBitmapWidth();xPixel++)
{
m_Lead1.SetPixel(xPixel,yPixel,xycolor);
}
m_Lead1.ForceRepaint();
}