M
martinsino
Unregistered / Unconfirmed
GUEST, unregistred user!
var
Form1: TForm1;
pHeight,pWidth:integer;
pLineByteArray;
p:array of integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.OpenPictureDialog1.Filter := '*.bmp|*.bmp';
if self.OpenPictureDialog1.Execute then
begin
Image1.Picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i,j:integer;
Gray:integer;
begin
Image1.Picture.Bitmap.HandleType:=bmDIB;
Image1.Picture.Bitmap.pixelFormat:=pf24bit;
pHeight:=Image1.Picture.Bitmap.Height;
pWidth:=Image1.Picture.Bitmap.Width;
//图像灰度化
for i:=0 to pHeight-1 do
begin
pLine:=Image1.Picture.Bitmap.ScanLine;
for j:=0 to pWidth-1 do
begin
Gray:=round(0.11*pLine[3*j]+0.59*pLine[3*j+1]+0.3*pLine[3*j+2]);
p[i*pWidth+j]:=Gray;
pLine[3*j]:=byte(Gray);
pLine[3*j+1]:=byte(Gray);
pLine[3*j+2]:=byte(Gray);
//p[i*pWidth+j]:=Gray; 记录每个点的灰度值
end;
end;
Image1.Invalidate;
end;
end.
这段程序在不加屏蔽掉的那一行,可以正常运行(灰度化).但是家了记录各点灰度值的语句(也就是屏蔽的那行),程序运行就出现内存错误,是什么原因啊!小弟下面的工作(2值化)需要用到这个参数.不知道各位大侠有没有什么好的解决方法```
谢谢
Form1: TForm1;
pHeight,pWidth:integer;
pLineByteArray;
p:array of integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.OpenPictureDialog1.Filter := '*.bmp|*.bmp';
if self.OpenPictureDialog1.Execute then
begin
Image1.Picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i,j:integer;
Gray:integer;
begin
Image1.Picture.Bitmap.HandleType:=bmDIB;
Image1.Picture.Bitmap.pixelFormat:=pf24bit;
pHeight:=Image1.Picture.Bitmap.Height;
pWidth:=Image1.Picture.Bitmap.Width;
//图像灰度化
for i:=0 to pHeight-1 do
begin
pLine:=Image1.Picture.Bitmap.ScanLine;
for j:=0 to pWidth-1 do
begin
Gray:=round(0.11*pLine[3*j]+0.59*pLine[3*j+1]+0.3*pLine[3*j+2]);
p[i*pWidth+j]:=Gray;
pLine[3*j]:=byte(Gray);
pLine[3*j+1]:=byte(Gray);
pLine[3*j+2]:=byte(Gray);
//p[i*pWidth+j]:=Gray; 记录每个点的灰度值
end;
end;
Image1.Invalidate;
end;
end.
这段程序在不加屏蔽掉的那一行,可以正常运行(灰度化).但是家了记录各点灰度值的语句(也就是屏蔽的那行),程序运行就出现内存错误,是什么原因啊!小弟下面的工作(2值化)需要用到这个参数.不知道各位大侠有没有什么好的解决方法```
谢谢