这是copyrect地版本,bitblt自己改一下(不同函数而已)
如果这个还不满意,那我没法子了!动手改改吧!
procedure TMainForm.run2centerClick(Sender: TObject);
var
newbmp: TBitmap;
i, bmpheight, bmpwidth: integer;
ratio: real;
Rect1, Rect2, Rect3, Rect4: Trect;
begin
childForm.DoubleBuffered := true;
newbmp := TBitmap.Create;
newbmp.Width := childForm.image1.Width;
newbmp.Height := childForm.image1.Height;
bmpheight := childForm.image1.Picture.Graphic.Height;
bmpwidth := childForm.image1.Picture.Graphic.Width;
if bmpheight < bmpwidth - 1 then
begin
ratio := bmpwidth / bmpheight;
for i := 0 to round(bmpheight / 2) + 1 do { TODO : &Euml;&Auml;&iquest;é&Iacute;&not;&Ecirc;±&iquest;&frac12;±&acute; }
begin
application.ProcessMessages;
Rect1 := Rect(0, 0, bmpwidth, i);
Rect2 := Rect(0, bmpheight - i, bmpwidth, bmpheight);
Rect3 := Rect(0, 0, trunc(i * ratio), bmpheight);
Rect4 := Rect(bmpwidth - Trunc(i * ratio), 0, bmpwidth, bmpheight);
newbmp.Canvas.CopyRect(Rect1, childForm.Image1.Canvas, Rect1);
newbmp.Canvas.CopyRect(Rect2, childForm.Image1.Canvas, Rect2);
newbmp.Canvas.CopyRect(Rect3, childForm.Image1.Canvas, Rect3);
newbmp.Canvas.CopyRect(Rect4, childForm.Image1.Canvas, Rect4);
childForm.Canvas.Draw(0, 0, newbmp);
end;
newbmp.Free;
end;
if bmpheight > bmpwidth then { TODO : &Icirc;&raquo;&Iacute;&frac14;&cedil;&szlig;&acute;ó&Oacute;&Uacute;&iquest;í&Ecirc;± }
begin
ratio := bmpheight / bmpwidth;
for i := 0 to trunc(bmpwidth / 2) + 1 do
begin
Rect1 := Rect(0, 0, bmpwidth, trunc(i * ratio));
Rect2 := Rect(0, bmpheight - trunc(i * ratio), bmpwidth, bmpheight);
Rect3 := Rect(0, 0, i, bmpheight);
Rect4 := Rect(bmpwidth - i, 0, bmpwidth, bmpheight);
newbmp.Canvas.CopyRect(Rect1, childForm.Image1.Canvas, Rect1);
newbmp.Canvas.CopyRect(Rect2, childForm.Image1.Canvas, Rect2);
newbmp.Canvas.CopyRect(Rect3, childForm.Image1.Canvas, Rect3);
newbmp.Canvas.CopyRect(Rect4, childForm.Image1.Canvas, Rect4);
childForm.Canvas.Draw(0, 0, newbmp);
end;
newbmp.Free;
end;
end;