We have a function to export items and their images to an Excel file using an RDLC report. However, the user was always forced to export in smaller parts, because the dataset was growing too big.
After some checking, it seems that their images were all very large around 7 mega pixels…
So… I created a function to resize an image.
I’m not going to make this post too long, so here is the function:
ResizeImage(VAR TempBlob : TEMPORARY Record TempBlob;UpsizeIfSmaller : Boolean;MaintainAspectRatio : Boolean;NewWidth : Integer;NewHeight : Integer)
IF (NewWidth = 0) OR (NewHeight = 0) THEN
Bitmap := Bitmap.Bitmap(Instr);
IF NOT UpsizeIfSmaller THEN
IF (NewWidth >= Bitmap.Width) OR (NewHeight >= Bitmap.Height) THEN
IF Bitmap.Width / NewWidth < Bitmap.Height / NewHeight THEN
AspectRatio := Bitmap.Width / NewWidth
AspectRatio := Bitmap.Height / NewHeight;
IF MaintainAspectRatio THEN BEGIN
NewHeight := Bitmap.Height / AspectRatio;
NewWidth := Bitmap.Width / AspectRatio;
Bitmap := Bitmap.Bitmap(Bitmap,NewWidth,NewHeight);
These are the variables:
Bitmap DotNet System.Drawing.Bitmap.'System.Drawing, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
ImageFormat DotNet System.Drawing.Imaging.ImageFormat.'System.Drawing, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
One more heads-up, but I’ll put an extra blog post for this:
You notice that I put a clear of the blob before creating the outstream to it.
If I don’t clear that, only the first part of the old blob data is overwritten, while the larger part of the previous blob remains in there…
Check this post for more information.