Timage控件中读取一个像素的话,有两种办法:1. TImage.Canvas.Pixels[X, Y],你需要指出坐标的.2.p: Pointer; p := Timage.Scanline[Y]; 然后移动这个指针来读取像素.都是要由用户提供坐标的.如果是知道了像素的颜色,要读坐标,就要用循环判断了.至于记录,方法太多了,像写入数据库,文本,都可以的.每个像素都是TColor类型的.
哈哈~ 这个我刚做过~~ 我做的是先二值化一个位图,这样他就只有两种色了比如黑和白procedure TForm1.Button2Click(Sender: TObject); var p:pbytearray; x,y:integer; bmp:tbitmap; begin bmp:=tbitmap.Create; bmp.Assign(form1.Image1.Picture.Bitmap); bmp.PixelFormat:=pf24bit; for y:=0 to bmp.Height-1 do begin p:=bmp.ScanLine[y]; for x:=0 to bmp.Width-1 do begin if (p[3*x+2]=0) and (p[3*x+1]=0) and (p[3*x]=0) then //p[3*x+2]=0) and (p[3*x+1]=0) and (p[3*x]=0) 就是代表黑色 begin edit1.Text:=inttostr(x); edit2.Text:=inttostr(y); // 这就记录下来了~ end; end; end; end;
p := Timage.Scanline[Y];
然后移动这个指针来读取像素.都是要由用户提供坐标的.如果是知道了像素的颜色,要读坐标,就要用循环判断了.至于记录,方法太多了,像写入数据库,文本,都可以的.每个像素都是TColor类型的.
我做的是先二值化一个位图,这样他就只有两种色了比如黑和白procedure TForm1.Button2Click(Sender: TObject);
var
p:pbytearray;
x,y:integer;
bmp:tbitmap;
begin
bmp:=tbitmap.Create;
bmp.Assign(form1.Image1.Picture.Bitmap);
bmp.PixelFormat:=pf24bit;
for y:=0 to bmp.Height-1 do
begin
p:=bmp.ScanLine[y];
for x:=0 to bmp.Width-1 do
begin
if (p[3*x+2]=0) and (p[3*x+1]=0) and (p[3*x]=0) then
//p[3*x+2]=0) and (p[3*x+1]=0) and (p[3*x]=0) 就是代表黑色
begin
edit1.Text:=inttostr(x);
edit2.Text:=inttostr(y); // 这就记录下来了~
end;
end;
end;
end;