Image AutoZoom

Hallo,
i have create a fastreport report on windows with FastReport.NET. The same Report does work on FastReport.Mono because of Image AutoZoom is not working. i search i the source code and found

src/FastReport.Mono/PictureObject.cs

case PictureBoxSizeMode.Zoom:
/*float kx = drawRect.Width / imageWidth;
float ky = drawRect.Height / imageHeight;
if (kx < ky)
rect.Height = imageHeight * kx;
else
rect.Width = imageWidth * ky;
rect.Offset(
(Width * e.ScaleX - rect.Width) / 2,
(Height * e.ScaleY - rect.Height) / 2);*/
break;

i have remove the block comment, recompile and all works.

Comments

  • edited 6:38PM
    Hallo,
    I have found a bug in your code (not my code)! Have anyone interrest in this ?????? That is really bad.
  • PolomintPolomint Australia
    edited 6:38PM
    If you believe you have found a bug in the Product, you should raise a Support Ticket, providing as much supporting information as possible.

    https://support.fast-report.com/users/sign_in

    Ideally you should create a minimal example that clearly replicates the problem.
  • Hello!

    The ‘preserve aspect ratio’ mode can be implemented using `SizeMode = PictureBoxSizeMode.StretchImage`, with the dimensions of the `PictureObject` first adjusted to match the image’s aspect ratio in the `BeforePrint` event handler:

    private void Picture1_BeforePrint(object sender, EventArgs e)
    {
      var pic = sender as PictureObject;
      if (pic?.Image != null)
      {
        float ratio = (float)pic.Image.Width / pic.Image.Height;
        float maxWidth = 100f; // maximum width
        float maxHeight = 100f; // maximum height
    
        if (ratio > 1)
        {
          pic.Width = maxWidth;
          pic.Height = maxWidth / ratio;
        }
        else
        {
          pic.Height = maxHeight;
          pic.Width = maxHeight * ratio;
        }
      }
    }
    

    This issue has been fully resolved in the latest versions of the FastReport.Core\FastReport.Core.Skia packages. The PictureObject component uses the native SkiaSharp / GDI+ engine, where `SizeMode.Zoom` preserves the aspect ratio and centres the image perfectly on all operating systems (Linux, macOS, Windows).

This discussion has been closed.