假设你的线都是水平线而且背景是白色线条是黑色,那么这个函数可以帮你找到最长线条所在的X坐标,其余可以参照这个函数去做了 function MaxLine(BMP: TBitmap): Integer; var x, y, tempMax, Max, tempInt: Integer; begin for y := 0 to BMP.Height do begin tempMax := 0; Max := 0; for x := 0 to BMP.Width do begin if BMP.Canvas.Pixels[x,y] = clBlack then Inc(tempMax); if (BMP.Canvas.Pixels[x,y] = clWhite) and (tempMax > Max) then begin Max := tempMax; Result := x; tempMax := 0; end;//if end;//for x end;//for y end;
function MaxLine(BMP: TBitmap): Integer;
var
x, y, tempMax, Max, tempInt: Integer;
begin
for y := 0 to BMP.Height do
begin
tempMax := 0;
Max := 0;
for x := 0 to BMP.Width do
begin
if BMP.Canvas.Pixels[x,y] = clBlack then Inc(tempMax);
if (BMP.Canvas.Pixels[x,y] = clWhite) and (tempMax > Max) then
begin
Max := tempMax;
Result := x;
tempMax := 0;
end;//if
end;//for x
end;//for y
end;