2

I am very new to multi device programming in XE10 Firemonkey and wonder if someone can help me with a problem reading the pixel colour from a bitmap.

What I want to do is sample a colour from a bitmap in a Timage control (like the way an eyedropper colour sampler works). I am showing the colour under the cursor in a TRectangle control.

This is my code in an onmousemove event over the image

procedure TMountboardForm.imagemountboardMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Single);
var
  vBitMapData : TBitmapData;
  ASelectionColor : TAlphaColor;
begin
if imagemountboard.bitmap.Map (TMapAccess.maread, vBitMapData) then
begin
  try
   ASelectionColor := vBitmapData.GetPixel (round(X), round(Y)); 
  finally
    imagemountboard.bitmap.Unmap(vBitMapData);
  end;
  rectangle1.Fill.Color :=  ASelectionColor;
end;
end;

This 'sort-of' works but the X & Y coordinates appear to be wrong. It picks up a colour some way away from the cursor rather than the colour under the cursor itself

Can someone tell me where I am going wrong?

Peter
  • 61
  • 1
  • 3
  • I have discovered the cause of the problem. The image wrap mode was set to 'fit' so the image was reduced in size, If I change to 'original' the code works but I have lost some of the image. I think I need to multiply the X and Y values by the amount the image has been compressed in each axis – Peter Jan 28 '17 at 15:19
  • Have you found a better solution yet? – Shaun Roselt Aug 31 '17 at 07:53

0 Answers0