最近在学习图片编程,这个问题折腾了半个月了,请路过的大虾帮看一下,谢了.要实现在功能是:,当发现图片里的行有固定颜色时,找出这一行所在的位置..
为什么我的代码找不出来啊?
如何改?
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
P:array[0..100] of PByteArray;//像素数组
L:array[0..100] of SHORT;//记录特定颜色行的位置
x,y,i:Integer;
Line:String;
IsExit:Boolean;
Bmp1:TBitmap;
begin
i:=0;
Line:='';
Bmp1:=TBitmap.Create;
Bmp1:=Image1.Picture.Bitmap;
Bmp1.PixelFormat:=pf24bit;
//ShowMessage(IntToStr(Image1.Picture.Bitmap.Width)+','+IntToStr(Image1.Picture.Bitmap.Height));
for y:=0 to Bmp1.Height-1 do
begin
P[y]:=Bmp1.ScanLine[y];//将图片所有像素值存入P
for x := 0 to Bmp1.Width-1 do
begin
try
if P[y]=nil then exit;
//当颜色是某一种时
if P[y][x*3]=210 then
if P[y][x*3+1]=60 then
if P[y][x*3+2]=50 then
begin
L[i]:=y;//记录所在行
Line:=IntToStr(y)+',';
Inc(i);
end;
except
//ShowMessage(IntToStr(x)+','+IntToStr(y));
//Continue;
end;
//next;
end;
//next;
end;
ShowMessage(Line);
Bmp1.Free; end;
为什么我的代码找不出来啊?
如何改?
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
P:array[0..100] of PByteArray;//像素数组
L:array[0..100] of SHORT;//记录特定颜色行的位置
x,y,i:Integer;
Line:String;
IsExit:Boolean;
Bmp1:TBitmap;
begin
i:=0;
Line:='';
Bmp1:=TBitmap.Create;
Bmp1:=Image1.Picture.Bitmap;
Bmp1.PixelFormat:=pf24bit;
//ShowMessage(IntToStr(Image1.Picture.Bitmap.Width)+','+IntToStr(Image1.Picture.Bitmap.Height));
for y:=0 to Bmp1.Height-1 do
begin
P[y]:=Bmp1.ScanLine[y];//将图片所有像素值存入P
for x := 0 to Bmp1.Width-1 do
begin
try
if P[y]=nil then exit;
//当颜色是某一种时
if P[y][x*3]=210 then
if P[y][x*3+1]=60 then
if P[y][x*3+2]=50 then
begin
L[i]:=y;//记录所在行
Line:=IntToStr(y)+',';
Inc(i);
end;
except
//ShowMessage(IntToStr(x)+','+IntToStr(y));
//Continue;
end;
//next;
end;
//next;
end;
ShowMessage(Line);
Bmp1.Free; end;
if P[y][x*3+1]=60 then
if P[y][x*3+2]=50 then颜色值的RGB是这样的吗? R:210;G:60;B:50??
if P[y][x*3+1]=60 then
if P[y][x*3+2]=210 then
我要的是全部是白色的那一行?procedure TForm1.SpeedButton2Click(Sender: TObject);
var
P:array[0..1000] of PByteArray;//像素数组
L:array[0..1000] of SHORT;//记录特定颜色行的位置
x,y,i:Integer;
Line:String;
IsExit:Boolean;
Bmp1:TBitmap;
begin
Line:='';
Cursor:=crHourGlass;
Bmp1:=TBitmap.Create;
Bmp1:=Image1.Picture.Bitmap;
Bmp1.PixelFormat:=pf24bit;
ShowMessage(IntToStr(Image1.Picture.Bitmap.Width)+','+IntToStr(Image1.Picture.Bitmap.Height)); IsExit:=false;
for y:=0 to Bmp1.Height-1 do
begin
P[y]:=Bmp1.ScanLine[y];//将图片所有像素值存入P
IsExit:=false;
for x := 0 to Bmp1.Width-1 do
begin
try
if P[y]=nil then exit;
//当白色时
if P[y][x*3]=255 then
if P[y][x*3+1]=255 then
if P[y][x*3+2]=255 then
begin
IsExit:=True;
end else
begin
IsExit:=False;
end;
except
//ShowMessage(IntToStr(x)+','+IntToStr(y));
//Continue;
end;
next;
end;
if IsExit=true then
begin
Line:=Line+IntToStr(y)+',';
end;
next;
end;
Cursor:=crDefault;
ShowMessage(Line);end;
var
P:array[0..1000] of PByteArray;//像素??
L:array[0..1000] of SHORT;//??特定?色行的位置
x,y,i:Integer;
Line:String;
IsExit:Boolean;
Bmp1:TBitmap;
begin
Line:='';
Cursor:=crHourGlass;
Bmp1:=TBitmap.Create;
Bmp1:=Image1.Picture.Bitmap;
Bmp1.PixelFormat:=pf24bit;
ShowMessage(IntToStr(Image1.Picture.Bitmap.Width)+','+IntToStr(Image1.Picture.Bitmap.Height)); //IsExit:=false;
for y:=0 to Bmp1.Height-1 do
begin
P[y]:=Bmp1.ScanLine[y];//??片所有像素值存入P
IsExit:=True;
for x := 0 to Bmp1.Width-1 do
begin
try
if P[y]=nil then exit;
//?白色?
if P[y][x*3]=255 then
if P[y][x*3+1]=255 then
if P[y][x*3+2]=255 then
begin
//IsExit:=True;
end else
begin
IsExit:=False;
Break;
end;
except
//ShowMessage(IntToStr(x)+','+IntToStr(y));
//Continue;
end; //next;
end;
if IsExit=true then
begin
Line:=Line+IntToStr(y)+',';
end;
//next;
end;
Cursor:=crDefault;
ShowMessage(Line);
end;
(P[y][x*3+1]<>255) or
)P[y][x*3+2]<>255) then
begin
IsExit:=False;
Break;
end;
(P[y][x*3+1]<>255) or
(P[y][x*3+2]<>255) then
begin
IsExit:=False;
Break;
end