I want to convert a SVG file to PNG file programmatically.
I'm using Delphi 10.3.3 with Skia4Delphi, but this code snippet doesn't respect transparency. It creates black background.
var
LBitmap: TBitmap;
MyPng: TPNGImage;
begin
if opendialog1.Execute then
begin
LBitmap := TBitmap.Create;
try
LBitmap.SetSize(1000,1000);
LBitmap.Transparent := True;
LBitmap.SkiaDraw(
procedure (const ACanvas: ISKCanvas)
var
LSvgBrush: TSkSvgBrush;
begin
LSvgBrush := TSkSvgBrush.Create;
try
LSvgBrush.Source := TFile.ReadAllText(opendialog1.FileName);
LSvgBrush.Render(ACanvas, RectF(0, 0, LBitmap.Width, LBitmap.Height), 1);
finally
LSvgBrush.Free;
end;
end);
if savedialog1.Execute then
begin
MyPng := TPngImage.Create;
try
MyPng.Assign(LBitmap);
MyPng.SaveToFile(savedialog1.FileName);
finally
MyPng.Free;
end;
end;
finally
LBitmap.Free;
end;
end;
end;