Pixel example for Delphi

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.

procedure TForm1.LEADRasterView1MouseDown (Sender: TObject; Button,
  Shift: Smallint; x, y: Single);
var
   sRet: Smallint;
   xycolor: longint;
   xfraction: Single;
   yfraction: Single;
   xPixel: Longint;
   yPixel: Longint;
begin
   //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:= Trunc((LEADRasterView1.SrcWidth * xfraction) + LEADRasterView1.SrcLeft);
   yPixel:= Trunc((LEADRasterView1.SrcHeight * yfraction) + LEADRasterView1.SrcTop);
   //Make the whole line the same color as the pixel.
   xycolor:= Trunc((LEADRasterView1.Raster.Pixel [xPixel, yPixel]));
   for xPixel:= 0 to Trunc(LEADRasterView1.Raster.BitmapWidth) - 1 do
      LEADRasterView1.Raster.Pixel[xPixel, yPixel]:= xycolor;
   LEADRasterView1.ForceRepaint (sRet);
end;