delphi - 如何设置 FMX.Canvas 上光标下像素的颜色?

标签 delphi firemonkey delphi-xe4

对于 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 Canvas 设置 X、Y 处的颜色?

最佳答案

根据这个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)中引入的。

关于delphi - 如何设置 FMX.Canvas 上光标下像素的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19214827/

相关文章:

c++ - 鼠标钩子(Hook)代码内部的调用方法导致访问冲突

delphi - 使用 FireMonkey 的 Mac OS 应用程序数据文件夹

delphi - 如何在Delphi XE4中对CSIDL或KNOWFOLDERID进行条件编译?

delphi - 如何将 MIDAS.DLL 嵌入客户端可执行文件中

delphi - 在 ZipForge 中手动创建事件处理程序

delphi - 用不同的编译器指令编译DELPHI代码

oracle - 测试 Delphi 应用程序的最佳方法

delphi - 如何使用FireMonkey截图(多平台)

ios - FireMonkey,IOS FMX.Listview

Delphi - OnKeyPress 在 TStringGrid 用新字符更新单元格之前发生