SVGIconImageList
SVGIconImageList copied to clipboard
Rendering issue with image32 when changing the image size
The following test program generates png images of different sizes. It is noticeable, that when changing the size from 32x32 to 256x256 (Test-2) the border appears angled. After clearing and reassigning the svg source (Test-3), this effect disappears.
var
FSvg : ISvg;
s : string;
begin
FSVG:=GetImage32SVGFactory.NewSvg;
FSVG.LoadFromFile('Test.svg');
s:=FSVG.Source;
SVGExportToPng(32,32,FSVG,'Test-1.png');
SVGExportToPng(256,256,FSVG,'Test-2.png');
FSVG.Clear;
FSVG.Source:=s;
SVGExportToPng(256,256,FSVG,'Test-3.png');
end.
Example image to illustrate the issue:
I have now investigated the problem further. After loading the Svg source file in Img32.SVG.Reader the LoadInternal function is called to calculate the paths. The number of interpolation points to flatten the paths depends on the size of the image.
In the example program, this calculation is first carried out for a size of 32x32. In the subsequent call for a 256x256 image, the drawing is made with the same number of interpolation points, which causes the angular structure. The problem should therefore been solved if the internal function fSvgReader.LoadInternal is called when changing the target size in order to trigger a recalculation of the interpolation points.
A possible fix in Image32SVGFactory:
procedure TImage32SVG.PaintTo(DC: HDC; R: TRectF; KeepAspectRatio: Boolean);
...
//Define Image32 output size
with FImage32 do begin
w:=Round(R.Width); h:=Round(R.Height);
chg:=(Width<>w) or (Height<>h);
SetSize(w,h);
if chg then fSvgReader.LoadInternal;
end;
To use this fix LoadInternal must be moved from private to public in Img32.SVG.Reader
A sample image to demonstrate the problem:
Reported to Image32 project: https://github.com/AngusJohnson/Image32/issues/161
Fixed in 4.4.6 version