新手初级问题:如何在自己的程序中使用朋友的源码 (50分)

L

liuer

Unregistered / Unconfirmed
GUEST, unregistred user!
我看到了ehom (?!) 朋友的图像旋转的源码,却不知怎么和自己窗口联系起来。问题是初级
些,请朋友们不要见笑啊。

//旋转90度
procedure Rotate90(const Bitmap:TBitmap);
var
i,j:Integer;
rowIn,rowOut:pRGBTriple;
Bmp:TBitmap;
Width,Height:Integer;
begin
Bmp:=TBitmap.Create;
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
Bmp.PixelFormat := pf24bit;
Width:=Bitmap.Width-1;
Height:=Bitmap.Height-1;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
for i := 0 to Width do
begin
rowOut := Bmp.ScanLine;
Inc(rowOut,Height - j);
rowOut^ := rowIn^;
Inc(rowIn);
end;
end;
Bitmap.Assign(Bmp);
end;

我想在自己的窗口上打开一图像文件,加一按钮,按一下这按钮图像就旋转90度,主要是想
知道上面这个函数参数该如何传递给按钮?
谢谢。
 
图象放在TBitmap中传给procedure Rotate90,按一下这按钮,只要调用Rotate90就行
 
写一下具体的参数传递好吗?
 
把这个过程序贴到你的程序的implimiion什么的后面:)
然后呢在一个按钮的click事件中写上一句Rotate90(image1.canvas.bitmap);

image1.canvas.bitmap//这个不敢确定也许是image1.picture.bitmap之类的东西你要
自己试一下或请别的DFW提示一下


 
把这个过程序贴到你的程序的implimiion什么的后面:)
然后呢在一个按钮的click事件中写上一句Rotate90(image1.canvas.bitmap);

image1.canvas.bitmap//这个不敢确定也许是image1.picture.bitmap之类的东西你要
自己试一下或请别的DFW提示一下
应该是image1.picture.bitmap
 
谢谢楼上两位,搞定了
 
下面的代码也是ehom朋友写的代码,可我为什么不能成功调用呢?请大家帮我看看参数对不对?
我觉得自己没有调用错啊

//任意角度
function RotateBitmap(Bitmap:TBitmap;Angle:Integer;BackColor:TColor):TBitmap;
var
i,j,iOriginal,jOriginal,CosPoint,SinPoint : integer;
RowOriginal,RowRotated : pRGBTriple;
SinTheta,CosTheta : Extended;
AngleAdd : integer;
begin
Result:=TBitmap.Create;
Result.PixelFormat := pf24bit;
Result.Canvas.Brush.Color:=BackColor;
Angle:=Angle Mod 360;
if Angle<0 then Angle:=360-Abs(Angle);
if Angle=0 then
Result.Assign(Bitmap)
else if Angle=90 then
begin
Result.Assign(Bitmap);
Rotate90(Result);//如果是旋转90度,直接调用上面的代码
end
else if (Angle>90) and (Angle<180) then
begin
AngleAdd:=90;
Angle:=Angle-AngleAdd;
end
else if Angle=180 then
begin
Result.Assign(Bitmap);
Rotate180(Result);//如果是旋转180度,直接调用上面的过程
end
else if (Angle>180) and (Angle<270) then
begin
AngleAdd:=180;
Angle:=Angle-AngleAdd;
end
else if Angle=270 then
begin
Result.Assign(Bitmap);
Rotate270(Result);//如果是旋转270度,直接调用上面的过程
end
else if (Angle>270) and (Angle<360) then
begin
AngleAdd:=270;
Angle:=Angle-AngleAdd;
end
else
AngleAdd:=0;
if (Angle>0) and (Angle<90) then
begin
sincos((Angle + AngleAdd) * Pi / 180, SinTheta, CosTheta);
if (SinTheta * CosTheta) < 0 then
begin
Result.Width := Round(Abs(Bitmap.Width * CosTheta - Bitmap.Height * SinTheta));
Result.Height := Round(Abs(Bitmap.Width * SinTheta - Bitmap.Height * CosTheta));
end
else
begin
Result.Width := Round(Abs(Bitmap.Width * CosTheta + Bitmap.Height * SinTheta));
Result.Height := Round(Abs(Bitmap.Width * SinTheta + Bitmap.Height * CosTheta));
end;
CosTheta:=Abs(CosTheta);
SinTheta:=Abs(SinTheta);
if (AngleAdd=0) or (AngleAdd=180) then
begin
CosPoint:=Round(Bitmap.Height*CosTheta);
SinPoint:=Round(Bitmap.Height*SinTheta);
end
else
begin
SinPoint:=Round(Bitmap.Width*CosTheta);
CosPoint:=Round(Bitmap.Width*SinTheta);
end;
for j := 0 to Result.Height-1 do
begin
RowRotated := Result.Scanline[j];
for i := 0 to Result.Width-1 do
begin
Case AngleAdd of
0:
begin
jOriginal := Round((j+1)*CosTheta-(i+1-SinPoint)*SinTheta)-1;
iOriginal := Round((i+1)*CosTheta-(CosPoint-j-1)*SinTheta)-1;
end;
90:
begin
iOriginal := Round((j+1)*SinTheta-(i+1-SinPoint)*CosTheta)-1;
jOriginal := Bitmap.Height-Round((i+1)*SinTheta-(CosPoint-j-1)*CosTheta);
end;
180:
begin
jOriginal := Bitmap.Height-Round((j+1)*CosTheta-(i+1-SinPoint)*SinTheta);
iOriginal := Bitmap.Width-Round((i+1)*CosTheta-(CosPoint-j-1)*SinTheta);
end;
270:
begin
iOriginal := Bitmap.Width-Round((j+1)*SinTheta-(i+1-SinPoint)*CosTheta);
jOriginal := Round((i+1)*SinTheta-(CosPoint-j-1)*CosTheta)-1;
end;
end;
if (iOriginal >= 0) and (iOriginal <= Bitmap.Width-1)and
(jOriginal >= 0) and (jOriginal <= Bitmap.Height-1)
then
begin
RowOriginal := Bitmap.Scanline[jOriginal];
Inc(RowOriginal,iOriginal);
RowRotated^ := RowOriginal^;
Inc(RowRotated);
end
else
begin
Inc(RowRotated);
end;
end;
end;
end;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
RotateBitmap(image1.picture.bitmap,120,clBackground);//我这样调用函数,为什么程序执行时却不能旋转?
end;

end.
 
上面的代码有问题,至少忘了释放掉bmp,应该改为:
//旋转90度
procedure Rotate90(const Bitmap:TBitmap);
var
i,j:Integer;
rowIn,rowOut:pRGBTriple;
Bmp:TBitmap;
Width,Height:Integer;
begin
Bmp:=TBitmap.Create;
try
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
Bmp.PixelFormat := pf24bit;
Width:=Bitmap.Width-1;
Height:=Bitmap.Height-1;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
for i := 0 to Width do
begin
rowOut := Bmp.ScanLine;
Inc(rowOut,Height - j);
rowOut^ := rowIn^;
Inc(rowIn);
end;
end;
Bitmap.Assign(Bmp);
finally
Bmp.free;
end;
end;

 
try this:
procedure RotateBitmap(var Bitmap:TBitmap;Angle:Integer);
....
....
 
确实是,直接调用过程即可。
 
顶部