【问题标题】:How do you set the color of a pixel under the cursor on a FMX.Canvas?如何在 FMX.Canvas 上设置光标下像素的颜色?
【发布时间】:2023-03-08 00:54:01
【问题描述】:

用 vcl 我用这个:

procedure MovingDots(X, Y: Integer; ACanvas: TCanvas); stdcall;
begin
{$R-}
  Inc(ALooper);
  ACounter := ACounter shl 1; // Shift the bit left one
  if ACounter = 0 then
    ACounter := 1; // If it shifts off left, reset it
  if (ACounter and 224) > 0 then // Are any of the left 3 bits set?
    // FMX.Canvas does not have Pixels
    ACanvas.Pixels[X, Y] := ASelectionColor1 // Erase the pixel
  else
    ACanvas.Pixels[X, Y] := ASelectionColor2; // Draw the pixel
{$R+}
end;

如何在 FMX 画布中设置 X、Y 的颜色?

【问题讨论】:

  • 感谢您,但您应该在评论中添加您想要感谢的问题,而不是在其他问题的正文中。

标签: delphi firemonkey delphi-xe4


【解决方案1】:

根据这个example,这应该可以工作:

var
  vBitMapData : TBitmapData;
  ASelectionColor : TAlphaColor;
...
// Define ASelectionColor somewhere
// Get write access to the bitmap
if ACanvas.Bitmap.Map (TMapAccess.maWrite, vBitMapData) then
begin
  try
    vBitmapData.SetPixel (x, y, ASelectionColor); // set the pixel color at x, y
  finally
    ACanvas.Bitmap.Unmap(vBitMapData);
  end;
end; 

请注意,在 FM2 即 Delphi-XE3 中引入了锁定/解锁位图的映射策略。

【讨论】:

  • @DavidHeffernan,这不正确吗FMX.Graphics.TCanvas.Bitmap
  • 天哪,我好像是个盲人。昨天,当我得出结论 TCanvas 没有 Bitmap 属性时,我正准备写完全相同的答案。那好吧。至少你的眼睛工作! +1
  • 请注意,比在 Delphi 10.4 中,由于 TMapAccess.Write 的一些问题,此代码不起作用。替换为 TMapAccess.ReadWrite 有效。
猜你喜欢
  • 2015-02-28
  • 2011-11-06
  • 1970-01-01
  • 2022-01-20
  • 2015-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多