Von oben-nach-unten und von unten-nach-oben Geht ja schon gut, Kriege es aber im moment nicht auf die Reihe
von links nach rechts zu suchen und umgekehrt.. Scanline nimmt ja immer eine Horizontale Zeile
Delphi-Quellcode:
function TForm1.RemoveBlack(Picture: TBitmap): TBitmap;
type
PixArray = Array [1..3] of Byte;
var
p: ^PixArray;
FirstTop,FirstLeft, FirstBottom, FirstRight, h,w: Integer;
Pic: TBitmap;
begin
FirstTop:=-1;
FirstLeft:=-1;
FirstBottom:=-1;
FirstRight:=-1;
Pic:=TBitmap.Create;
Pic.Assign(Picture);
Pic.PixelFormat:=pf24bit;
For h:=0 to Pic.Height-1 do
begin
p:= Pic.ScanLine[h];
For w:=0 to Pic.Width-1 do
begin
if (p^[1]<>0) OR (p^[2]<>0) OR (p^[3]<>0) then
begin
FirstTop:=h;
break;
end;
inc(p)
end;
if (FirstTop >= 0) then break;
end;
For h:=Pic.Height-1 downto 0 do
begin
p:= Pic.ScanLine[h];
For w:=0 to Pic.Width-1 do
begin
if (p^[1]<>0) OR (p^[2]<>0) OR (p^[3]<>0) then
begin
FirstBottom:=h;
break;
end;
inc(p)
end;
if (FirstBottom >= 0) then break;
end;
Showmessage('Y1:' +inttostr(FirstTop)+'Y2:' +inttostr(FirstBottom));
end;