使用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的颜色?
答案 0 :(得分:3)
根据这个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。