有关copyrect(20分)

  • 主题发起人 主题发起人 true_feiyun
  • 开始时间 开始时间
T

true_feiyun

Unregistered / Unconfirmed
GUEST, unregistred user!
unit U1_424;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
step=200;
x0=0;
y0=0;
var
bitmap:tbitmap;
midx:integer;
ratiox:real;
i:integer;
rect1,rect2:trect;
begin
bitmap:=tbitmap.Create;
bitmap.LoadFromFile('1.bmp');
ratiox:=bitmap.Width/step;
for i:=0 to step do
begin
midx:=round(ratiox*i);
with rect1 do
begin
left:=bitmap.Width-midx;
top:=0;
right:=bitmap.Width;
bottom:=bitmap.Height;
end;
with rect2 do
begin
left:=x0;
top:=y0;
right:=x0+midx;
bottom:=y0+bitmap.height;
end;
canvas.CopyRect(rect2,bitmap.Canvas,rect1);
end;
bitmap.Free;
end;
end.

以上代码把一副图象从左向右显示,请问如何修改代码,
让图象从右向左,从上到下,从下到上显示呢(用copyrect的方法)
 
我有一段代码,你看看:
procedure TMainForm.up2downClick(Sender: TObject);//由上往下
var
newbmp: TBitmap;
i, bmpheight, bmpwidth: integer;
begin
newbmp := TBitmap.Create;
newbmp.Width := ChildForm.image1.Width;
newbmp.Height := ChildForm.image1.Height;
bmpheight := ChildForm.image1.Height;
bmpwidth := ChildForm.image1.Width;
childForm.DoubleBuffered := True;
for i := 1 to bmpheight do
begin

newbmp.Canvas.CopyRect(Rect(0, 0, bmpwidth, i), ChildForm.image1.Canvas,
Rect(0, bmpheight - i, bmpwidth, bmpheight));
application.ProcessMessages;
ChildForm.canvas.Draw(0, 0, newbmp);
end;

childForm.invalidate;
newbmp.free;
end;
由左往右
procedure TMainForm.left2rightClick(Sender: TObject);
var
newbmp: TBitmap;
i, bmpheight, bmpwidth: integer;
begin
newbmp := TBitmap.Create;
newbmp.Width := ChildForm.image1.Width;
newbmp.Height := ChildForm.image1.Height;
bmpheight := ChildForm.image1.Height;
bmpwidth := ChildForm.image1.Width;
childForm.DoubleBuffered := True;
for i := 0 to bmpwidth do
begin
newbmp.Canvas.CopyRect(Rect(0, 0, i, bmpheight), ChildForm.image1.Canvas,
Rect(0, 0, i, bmpheight));
ChildForm.canvas.Draw(0, 0, newbmp);
application.ProcessMessages;

end;

childForm.invalidate;
newbmp.free;
end;
其他的可以自己稍微改一下!
 
还有从左上角到右下角,右上角到左下角的
procedure TForm1.LUConerToRDConer();//从左上角到右下角
var i,step:integer;
bitmap:TBitmap;
x,y,rx,ry:single;
begin
bitmap:=Tbitmap.create;
bitmap.loadfromfile(filename);
rx:=bitmap.width/step;
ry:=bitmap.height/step;
for i:=0 to step do
begin
x:=round(rx*i);
y:=round(ry*i);
with RctSrc do
left:=0;
top:=0;
right:=x;
bottom:=y;
end;
with RectDest do
begin
left:=0
top:=0;
right:=x;
botom:=y;
end;
canvas.copyrect(rectdest,bitmap,rectsrc);
end;
bitmap.free
end;
右上角到左下角的只需改动如下:
letft:=bitmap.width-x;
top:=0;
right:=bitmap.width;
bottom:=y;
 
多人接受答案了。
 
后退
顶部