Pixel example for C++ Builder

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.

   long xycolor;
   float xfraction;
   float yfraction;
   long xPixel;
   long yPixel;

   //Translate mouse coordinates to fractions of the destination width and height.
   LEADRasterView1->BackErase = False;
   xfraction= (x - LEADRasterView1->DstLeft) / LEADRasterView1->DstWidth;
   yfraction= (y - LEADRasterView1->DstTop) / LEADRasterView1->DstHeight;
   //convert fractions to bitmap pixel coordinates.
   xPixel= (LEADRasterView1->SrcWidth * xfraction) + LEADRasterView1->SrcLeft;
   yPixel= (LEADRasterView1->SrcHeight * yfraction) + LEADRasterView1->SrcTop;
   //Make the whole line the same color as the pixel.
   xycolor= LEADRasterView1->Raster ->get_Pixel(xPixel, yPixel);
   for (xPixel= 0; xPixel < LEADRasterView1->Raster->BitmapWidth; xPixel ++)
      LEADRasterView1->Raster->set_Pixel (xPixel, yPixel, xycolor);
   LEADRasterView1->ForceRepaint ();