Recent

Author Topic: StretchDraw differences between Delphi and FPC  (Read 460 times)

OwlOfTime

  • Hero Member
  • *****
  • Posts: 3827
StretchDraw differences between Delphi and FPC
« on: March 05, 2021, 05:03:04 pm »
Hi, we have this function to resize a QR code that the original size is 77x77 to 231x231 (3x).

With LCL it works perfectly, but with Delphi the resulting image is blurred, like it uses some kind of antialiasing.

Anyone that's using Delphi knows why or how to fix? Thanks.

Code: Pascal  [Select][+][-]
  1. procedure ResizeBitmap(Bitmap: TBitmap; Width, Height: Integer; Background: TColor);
  2. var
  3.   R: TRect;
  4.   B: TBitmap;
  5.   X, Y: Integer;
  6. begin
  7.   if assigned(Bitmap) then begin
  8.     B:= TBitmap.Create;
  9.     try
  10.       if Bitmap.Width > Bitmap.Height then begin
  11.         R.Right:= Width;
  12.         R.Bottom:= ((Width * Bitmap.Height) div Bitmap.Width);
  13.         X:= 0;
  14.         Y:= (Height div 2) - (R.Bottom div 2);
  15.       end else begin
  16.         R.Right:= ((Height * Bitmap.Width) div Bitmap.Height);
  17.         R.Bottom:= Height;
  18.         X:= (Width div 2) - (R.Right div 2);
  19.         Y:= 0;
  20.       end;
  21.       R.Left:= 0;
  22.       R.Top:= 0;
  23.       B.PixelFormat:= Bitmap.PixelFormat;
  24.       B.Width:= Width;
  25.       B.Height:= Height;
  26.       B.Canvas.Brush.Color:= Background;
  27.       B.Canvas.FillRect(B.Canvas.ClipRect);
  28.       B.Canvas.StretchDraw(R, Bitmap);
  29.       Bitmap.Width:= Width;
  30.       Bitmap.Height:= Height;
  31.       Bitmap.Canvas.Brush.Color:= Background;
  32.       Bitmap.Canvas.FillRect(Bitmap.Canvas.ClipRect);
  33.       Bitmap.Canvas.Draw(X, Y, B);
  34.     finally
  35.       B.Free;
  36.     end;
  37.   end;
  38. end;
Just Why?

engkin

  • Hero Member
  • *****
  • Posts: 2817
Re: StretchDraw differences between Delphi and FPC
« Reply #1 on: March 05, 2021, 08:21:07 pm »
I don't know.

Checking the source for LCL, I see it uses StretchMaskBlt.

Compare: Canvas.CopyMode of both Bitmap and b, see if there is a difference between Delphi and LCL?

 

TinyPortal © 2005-2018