Page 1 of 1

How to control background color in TTeePolygon in TMapSeries when using a transparent svg or png image

Posted: Fri Jun 21, 2024 9:32 am
by 16596778
I am able to load a transparent png or svg into the TTeePolygon.Brush.Image property but the background color is always white. Is it possible to set the background to some other color?

Re: How to control background color in TTeePolygon in TMapSeries when using a transparent svg or png image

Posted: Tue Jun 25, 2024 9:21 pm
by yeray
Hello,

You could use OnAfterDraw event to manually draw transparent images with StretchDraw method on top of the polygons. Ie:

Code: Select all

uses Chart, TeeMapSeries, TeePng;

var Chart1: TChart;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1:=TChart.Create(Self);

  with Chart1 do
  begin
    Parent:=Self;
    Align:=alClient;
    Color:=clWhite;
    Gradient.Visible:=False;
    Walls.Back.Color:=clWhite;
    Walls.Back.Gradient.Visible:=False;
    Legend.Hide;
    View3D:=False;

    TMapSeries(AddSeries(TMapSeries)).FillSampleValues;

    OnAfterDraw:=Chart1AfterDraw;
  end;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i: Integer;
    map: TMapSeries;
    image: TPicture;
begin
  if not Assigned(Chart1) or (Chart1.SeriesCount<0) then
     Exit;

  image:=TPicture.Create;
  image.LoadFromFile('D:\tmp\transp.png');
  map:=TMapSeries(Chart1[0]);
  for i:=0 to map.Count-1 do
  begin
    Chart1.Canvas.ClipPolygon(map.Polygon[i].GetPoints, Length(map.Polygon[i].GetPoints));
    Chart1.Canvas.StretchDraw(map.Polygon[i].Bounds, image.Graphic);
    Chart1.Canvas.UnClipRectangle;
  end;
end;

Re: How to control background color in TTeePolygon in TMapSeries when using a transparent svg or png image

Posted: Wed Jul 10, 2024 10:30 am
by 16596778
Thanks, in the meanwhile I found a solution where I prepare the bitmap with a background color before assigning it to the polygon