在Delphi中裁剪并对齐插入的BMP [英] crop and align inserted BMP in Delphi
本文介绍了在Delphi中裁剪并对齐插入的BMP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想裁剪并对齐剪贴板中插入的BMP. 我正在尝试2天,但仍然无法正常工作...
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.
推荐答案
如果我理解正确,您是否需要将位图居中在Image控件中?
If I understand you right, you need to center the bitmap in the Image control?
很简单-设置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;
这篇关于在Delphi中裁剪并对齐插入的BMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文