首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

[]-帮看一下这个代码-

2013-07-08 
[求助]---------------大虾帮看一下这个代码-------------最近在学习图片编程,这个问题折腾了半个月了,请

[求助]---------------大虾帮看一下这个代码-------------
最近在学习图片编程,这个问题折腾了半个月了,请路过的大虾帮看一下,谢了.

要实现在功能是:,当发现图片里的行有固定颜色时,找出这一行所在的位置..


为什么我的代码找不出来啊?
如何改?


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.Button1Click(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:=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;

热点排行