Switch specific colors in a TPathData

  

I am using Delphi Rio with firemonkey. I generated a polygon form TBitmap that has transparent background and some text in black. I want to change the black color only to red color of the polygon and save the changes to the original Tbitmap?
I tried iteration through the points of the TPathData and change the individual pixels, but this process is time consuming.
Is there a faster way to do switch the colors of TPathData?
This is the procedure that uses iteration through TPathData points the change the color of the pixel.

procedure TForm1.ChangePathColor(Npath : TPathData; TopV : Integer; BotV : Integer);

var
Polygon: TPolygon;
Color: TAlphaColor;
MyBitmap : TBitmap;
BMPD, MBMPD : TBitmapData;
MyBitmapCopy: TBitmap;
access : TMapAccess;
h,v : integer;
begin
Npath.FlattenToPolygon(Polygon,1);
MyBitmap := TBitmap.Create(0, 0);
MyBitmap.Assign(Image1.Bitmap);
MyBitmapCopy := TBitmap.Create(0, 0);
MyBitmapCopy.Assign(MyBitmap);
try
if (MyBitmap.Map(access, BMPD) and (MyBitmapCopy.Map(access,MBMPD))) then
Begin
Try
for h := 1 to MyBitmap.Width do
for v := TopV to BotV do
begin
if image1.Canvas.PtInPath(pointf(h,v),Npath) then
begin
Color := BMPD.GetPixel(h,v);
if (TAlphaColorRec(Color).R < 50) then MBMPD.SetPixel(h,v, TAlphaColors.Red);
end;
end;
finally
MyBitmap.Unmap(BMPD);
MyBitmapCopy.Unmap(MBMPD);
end;
end;
Image1.Bitmap := MyBitmapCopy;
finally
MyBitmapCopy.Free;
MyBitmap.Free;
end;
end;

Excuse my poor English for misunderstanding. I will explain my problem in pictures
The User choose a verse by click and the verse is sent to color transformation procedure

This is option will highlight the verse and is very fast

This option will change the color of the verse and is very slow using the ChangePathColor procedure that change pixel by pixel

The whole new changed BitMap will be sent back the TImage.
I want to speed up the process for the colorizing option.

Comments are closed.