Pixel example for C++ 5.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::OnMouseDownLeadrasterview1(short Button, short Shift, float x, float y)
{
long xycolor;
float xfraction;
float yfraction;
float xPixel;
float yPixel;
// In MFC 4.0 you get pixels; so set the scalemode accordingly.
m_LEADRasterView1.SetScaleMode(3);
m_LEADRasterView1.SetAutoRepaint(FALSE);
// Translate mouse coordinates to fractions of the destination width and height.
xfraction = (x - m_LEADRasterView1.GetDstLeft()) / m_LEADRasterView1.GetDstWidth();
yfraction = (y - m_LEADRasterView1.GetDstTop()) / m_LEADRasterView1.GetDstHeight();
// Convert fractions to bitmap pixel coordinates.
xPixel = (m_LEADRasterView1.GetSrcWidth() * xfraction) + m_LEADRasterView1.GetSrcLeft();
yPixel = (m_LEADRasterView1.GetSrcHeight() * yfraction) + m_LEADRasterView1.GetSrcTop();
// Make the whole line the same color as the pixel.
xycolor = m_LEADRasterView1.GetRaster().GetPixel(xPixel, yPixel);
for(xPixel=0; xPixel<m_LEADRasterView1.GetRaster().GetBitmapWidth();xPixel++)
{
m_LEADRasterView1.GetRaster().SetPixel(xPixel,yPixel,xycolor);
}
m_LEADRasterView1.ForceRepaint();
}