crop and align inserted BMP in Delphi

狂风中的少年 提交于 2019-12-08 07:14:53

问题


I want to crop and align the inserted BMP from the clipboard. I'm trying for 2 days but still nothing workable...

procedure TForm1.act1Execute(Sender: TObject);
var
BMP : TBitmap;
begin
BMP := TBitmap.Create;
BMP.Assign(Clipboard);
BMP.SetSize(400,200);
Img1.picture.Graphic := BMP;
BMP.Free;
end;

procedure TForm1.act1Update(Sender: TObject);
begin
(Sender as TAction).Enabled := Clipboard.HasFormat(CF_BITMAP);
end;

end.

回答1:


If I understand you right, you need to center the bitmap in the Image control?

It's simple - set the Img1.Center := True

To crop the bitmap you need code like this:

    procedure CropBitmap(Bmp: TBitmap; const CropRect: TRect);
    var
      CropBmp: TBitmap;
    begin
      CropBmp := TBitmap.Create;
      try
        CropBmp.Width := CropRect.Right - CropRect.Left;
        CropBmp.Height := CropRect.Bottom - CropRect.Top;
        CropBmp.Canvas.CopyRect(
          Rect(0, 0, CropBmp.Width, CropBmp.Height),
          Bmp.Canvas,
          CropRect
        );
        Bmp.Assign(CropBmp);
      finally
        CropBmp.Free;
      end;
    end;


来源:https://stackoverflow.com/questions/17966034/crop-and-align-inserted-bmp-in-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!