title: Resize the canvas around a bitmap?
body: <p><strong>Take the below image I will use for the following examples:</strong></p>
  
  <p>The dimensions unchaged are currently <code>96 x 71</code></p>
  
  <p><img src="https://i.stack.imgur.com/pwCmH.png" alt="enter image description here"></p>
  
  <p>Lets say I wanted to resize the canvas to <code>115 x 80</code> - the resulting image should then be:</p>
  
  <p><img src="https://i.stack.imgur.com/NoeOk.png" alt="enter image description here"></p>
  
  <p>Finally if I resized it to a smaller size than the original canvas was, eg <code>45 x 45</code> the output would appear like so:</p>
  
  <p><img src="https://i.stack.imgur.com/i4YgA.png" alt="enter image description here"></p>
  
  <p><strong>This is what I have tried so far:</strong></p>
  
  <pre><code>procedure ResizeBitmapCanvas(Bitmap: TBitmap; H, W: Integer);
  var
    Bmp: TBitmap;
    Source, Dest: TRect;
  begin
    Bmp := TBitmap.Create;
    try
      Source := Rect(0, 0, Bitmap.Width, Bitmap.Height);
      Dest := Source;
      Dest.Offset(Bitmap.Width div 2, Bitmap.Height div 2);
      Bitmap.SetSize(W, H);
      Bmp.Assign(Bitmap);
      Bmp.Canvas.FillRect(Source);
      Bmp.Canvas.CopyRect(Dest, Bitmap.Canvas, Source);
      Bitmap.Assign(Bmp);
    finally
      Bmp.Free;
    end;
  end;
  
  procedure TForm1.Button1Click(Sender: TObject);
  begin
    ResizeBitmapCanvas(Image1.Picture.Bitmap, 110, 110);
  end;
  </code></pre>
  
  <p>If you try the above on a bitmap loaded into a TImage the actual bitmap does not center, the canvas does change size however.</p>
  
  <p>The properties I have set for the Image are:</p>
  
  <pre><code>Image1.AutoSize := True;
  Image1.Center   := True;
  Image1.Stretch  := False;
  </code></pre>
  
  <p>I think it could be the line <code>Dest.Offset(Bitmap.Width div 2, Bitmap.Height div 2);</code> which needs looking at, to calculate the correct center position?</p>
  
  <p>The code has been adapted/modified slightly from a recent question David Heffernan answered.</p>
  
  <p><strong>How do I resize the canvas that surrounds a bitmap, but without stretching the bitmap?</strong></p>