DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

ScaleBitmap (copy overload)

Performs a high quality scaling of bitmap ASrcBmp and copies the result into ADestBmp. The required scale factor is given by AScaling.

procedure ScaleBitmap(ADestBmp, ASrcBmp: Graphics.TBitmap; AScaling: Double);
  overload;
var
  OutRect: Types.TRect; // rectangle defining resized image
begin
  OutRect := ScaleRect(ASrcBmp.Canvas.ClipRect, AScaling);
  ADestBmp.Width := RectWidth(OutRect);
  ADestBmp.Height := RectHeight(OutRect);
  HalftoneStretch(
    ADestBmp.Canvas,
    ADestBmp.Canvas.ClipRect,
    ASrcBmp.Canvas,
    ASrcBmp.Canvas.ClipRect
  );
end;

ScaleBitmap (inplace overload)

Performs a high quality scaling of the given bitmap by scale factor AScaling. The bitmap is modified in place.

procedure ScaleBitmap(ABitmap: Graphics.TBitmap; AScaling: Double); overload;
var
  TempBmp: Graphics.TBitmap;
begin
  TempBmp := Graphics.TBitmap.Create;
  try
    TempBmp.PixelFormat := Graphics.pf24Bit;
    ScaleBitmap(TempBmp, ABitmap, AScaling);
    ABitmap.Assign(TempBmp);
  finally
    TempBmp.Free;
  end;
end;

ScaleRect

Scales the given rectangle by the given scale factor and returns the scaled rectangle.

function ScaleRect(const ARect: Types.TRect; AScaling: Double): Types.TRect;
begin
  Result.Left := System.Round(ARect.Left * AScaling);
  Result.Top := System.Round(ARect.Top * AScaling);
  Result.Right := System.Round(ARect.Right * AScaling);
  Result.Bottom := System.Round(ARect.Bottom * AScaling);
end;

View the whole database.

Go to the DelphiDabbler website.