【问题标题】:How do I identify the colour of a pixel at the location of a mouse click in Firemonkey?如何在 Firemonkey 中识别鼠标单击位置的像素颜色?
【发布时间】:2016-12-01 22:02:55
【问题描述】:

我在 VCL 中做过类似的事情。我绝不是专业人士,我不认为这是最好的方法,但这是我所拥有的:

pt := TImage(Sender).ScreenToClient(Mouse.CursorPos);
color := image1.Canvas.Pixels[pt.X, pt.Y];

考虑到图像/画布等的工作方式似乎有点不同,而且我对它很不熟悉,我基本上是在寻找一些帮助来有效地将这段代码移植到 firemonkey 中,以获得相同的结果。

提前致谢。

【问题讨论】:

    标签: delphi firemonkey vcl


    【解决方案1】:

    我猜你需要这样的东西:

    procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Single);
    var
      Cl: TAlphaColor;
      Dt: TBitmapData;
    begin
      if Image1.Bitmap.Map(TMapAccess.maRead, Dt) then
      begin
        Cl:= Dt.GetPixel(Trunc(X), Trunc(Y));
        Image1.Bitmap.Unmap(Dt);
      end;
    end;
    

    【讨论】:

      猜你喜欢
      • 2018-08-06
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多