nicht vollständig, aber als Ansatz ....
Delphi-Quellcode:
type
pRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = ARRAY[0..$effffff] OF TRGBTriple;
pRGBQuadArray = ^TRGBQuadArray;
TRGBQuadArray = ARRAY[0..$effffff] OF TRGBQuad;
Function CountBlack24(Bitmap: TBitmap):Integer;
var
X, Y: Integer;
NUL:TRGBTriple;
pLine: pRGBTripleArray;
begin
NUl.rgbtBlue := 0;
NUl.rgbtGreen := 0;
NUl.rgbtRed := 0;
Result := 0;
for Y := 0 to Bitmap.Height -1 do
begin
pLine := Bitmap.ScanLine[Y];
for X := 0 to Bitmap.Width -1 do
if (pLine[X].rgbtBlue=0) and (pLine[X].rgbtred=0) and (pLine[X].rgbtgreen=0) then inc(Result);
end;
end;
Function CountBlack32(Bitmap: TBitmap):Integer;
var
X, Y: Integer;
pLine: pRGBQuadArray;
begin
Result := 0;
for Y := 0 to Bitmap.Height -1 do
begin
pLine := Bitmap.ScanLine[Y];
for X := 0 to Bitmap.Width -1 do
if (pLine[X].rgbBlue=0) and (pLine[X].rgbred=0) and (pLine[X].rgbgreen=0) then inc(result);
end;
end;
Function CountBlack(Bitmap: TBitmap):Integer;
begin
if Bitmap.PixelFormat=pf24bit then Result := CountBlack24(Bitmap)
else Result:=CountBlack32(Bitmap)
end;
procedure TForm2.Button1Click(Sender: TObject);
var
i:Integer;
begin
for I := 0 to Image1.Width do
image1.Canvas.Pixels[i,i] := clBlack;
image1.Picture.Bitmap.PixelFormat := pf24bit;
Showmessage(IntToStr(CountBlack(image1.Picture.Bitmap)));
image1.Picture.Bitmap.PixelFormat := pf32bit;
Showmessage(IntToStr(CountBlack(image1.Picture.Bitmap)));
end;