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

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Lars Nebel
Newbie
Newbie
Posts: 2
Joined: Mon Sep 18, 2023 12:00 am

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

Post by Lars Nebel » Fri Jun 21, 2024 9:32 am

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?

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

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

Post by Yeray » Tue Jun 25, 2024 9:21 pm

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Lars Nebel
Newbie
Newbie
Posts: 2
Joined: Mon Sep 18, 2023 12:00 am

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

Post by Lars Nebel » Wed Jul 10, 2024 10:30 am

Thanks, in the meanwhile I found a solution where I prepare the bitmap with a background color before assigning it to the polygon

Post Reply