SVGIconImageList icon indicating copy to clipboard operation
SVGIconImageList copied to clipboard

Rendering issue with image32 when changing the image size

Open jrathlev opened this issue 5 months ago • 2 comments

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:

Image

jrathlev avatar Jun 13 '25 10:06 jrathlev

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.

jrathlev avatar Jun 14 '25 15:06 jrathlev

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:

test.zip

jrathlev avatar Jun 14 '25 17:06 jrathlev

Reported to Image32 project: https://github.com/AngusJohnson/Image32/issues/161

carloBarazzetta avatar Jul 03 '25 08:07 carloBarazzetta

Fixed in 4.4.6 version

carloBarazzetta avatar Jul 08 '25 06:07 carloBarazzetta