下面是我写的代码,但有错误,程序显示:Project Project1.exe raised exception class EInvalidGraphicOperation with message
'扫描线索引超界',Process stopped.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Image1: TImage;
Image2: TImage;
Image3: TImage;
top: TButton;
buttom: TButton;
exit: TButton;
interpolate: TButton;
savep: TButton;
Save: TSavePictureDialog;
Open: TOpenPictureDialog;
procedure topClick(Sender: TObject);
procedure buttomClick(Sender: TObject);
procedure exitClick(Sender: TObject);
procedure savepClick(Sender: TObject);
procedure interpolateClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ps1, ps2, pd: PByteArray;
bs1, bs2, bd: TBitmap;
i, j: integer;
implementation
{$R *.dfm}
procedure TForm1.topClick(Sender: TObject);
//打开上层图
var
filename:AnsiString;
begin
if(Open.Execute)then
begin
filename:=Open.FileName;
Image1.Picture.LoadFromFile(filename);
end;
end;
procedure TForm1.buttomClick(Sender: TObject);
//打开下层图
var
filename:AnsiString;
begin
if(Open.Execute)then
begin
filename:=Open.FileName;
Image2.Picture.LoadFromFile(filename);
end;
end;
procedure TForm1.exitClick(Sender: TObject);
//退出
begin
Close;
end;
procedure TForm1.savepClick(Sender: TObject);
//插值
var
filename:AnsiString;
begin
if Save.Execute then
begin
filename:=Save.FileName;
Save.DefaultExt:='.BMP';
Image3.Picture.SaveToFile(filename);
end;
end;
procedure TForm1.interpolateClick(Sender: TObject);
//插值
begin
bs1:=TBitmap.Create;
bs1.Assign(Image1.Picture.Bitmap);
bs2:=TBitmap.Create;
bs2.Assign(Image2.Picture.Bitmap);
bd:=TBitmap.Create;
for i:=0 to bs1.Height-1 do
begin
ps1:= bs1.ScanLine;
ps2:= bs2.ScanLine;
pd:= bd.ScanLine;
for j:= 0 to bs1.Width-1 do
begin
pd[j]:=(ps1[j] + ps2[j]) div 2;
end;
end;
Image3.Picture.Bitmap.Assign(bd);
end;
end.
请问错在那?