PixelData 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 CTutorDlg::OnMouseDownLeadrasterview1 (short Button, short Shift, float x, float y)
{
ILEADRasterVariant * pltRasVar = NULL;
float xfraction;
float yfraction;
float xPixel;
float yPixel;
CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL,
IID_ILEADRasterVariant, (void **)&pltRasVar);
// In MFC you get pixels; so set the scale mode accordingly.
m_RasterView1.GetRaster().SetScaleMode(3);
m_RasterView1.SetAutoRepaint(FALSE);
// Translate mouse coordinates to fractions of the destination width and height.
xfraction = (x - m_RasterView1.GetDstLeft()) / m_RasterView1.GetDstWidth();
yfraction = (y - m_RasterView1.GetDstTop()) / m_RasterView1.GetDstHeight();
// Convert fractions to bitmap pixel coordinates.
xPixel = (m_RasterView1.GetSrcWidth() * xfraction) + m_RasterView1.GetSrcLeft();
yPixel = (m_RasterView1.GetSrcHeight() * yfraction) + m_RasterView1.GetSrcTop();
// Make the whole line the same color as the pixel.
pltRasVar = m_RasterView1.GetRaster ().GetPixelData(xPixel, yPixel);
//disable repainting
m_RasterView1.SetAutoRepaint (FALSE);
for(xPixel=0; xPixel<m_RasterView1.GetRaster().GetBitmapWidth();xPixel++)
{
m_RasterView1.GetRaster().SetPixelData(xPixel,yPixel,pltRasVar);
}
// re-enable repainting
m_RasterView1.SetAutoRepaint (TRUE);
pltRasVar->Release();
}