Thema: Delphi Bitmap in SW umwandeln

Einzelnen Beitrag anzeigen

DocZenith

Registriert seit: 8. Feb 2006
27 Beiträge
 
#7

Re: Bitmap in SW umwandeln

  Alt 11. Feb 2006, 19:07
Also hab jetzt eine Prozedure geschrieben, die ein Videobild (Graustufen) aufnimmt,
es in ein 8Bit sw Bild umwandelt. Ich möchte aber das das Bild ein 1Bit sw Bild ist,
wobei 1 für weiß und 0 für schwarz steht, da es ja bei 1Bit nur 1 oder 0 geht.
Dadurch benötigt das Bild weniger speicher als ein 8 Bit bild. aber wenn die schleife durchläuft,
die das bild in 1 Bit runterrechnet, bleibt das bild leider immer schwarz. warum weiß ich leider
nicht. Vielleicht findet ihr den fehler. wäre froh wenn mir jemand helfen könnte.

Delphi-Quellcode:
procedure TMainForm.Timer1Timer(Sender: TObject);
var
  PixelLine: PByteArray;
  x, y,xzahl,yzahl: integer;
  Bitmap: TBitmap;
  schwellwert,bildpunkte: integer;
begin

  { neues Videobild holen und darstellen - Bild ist bereits Graustufen }
GrabVideoImage;
Bitmap := VideoImage;
bildpunkte := 0;

  { Schwellwert für Bild ermitteln  - Mittelwert }
for y := 0 to Bitmap.height - 1 do
  begin
    yzahl := 1;
    PixelLine := Bitmap.ScanLine[y];
    yzahl := yzahl + y;
    for x := 0 to Bitmap.width - 1 do
    begin
       xzahl := 1;
       xzahl := xzahl + x;
       bildpunkte := bildpunkte + pixelline[x];
    end;
       schwellwert := xzahl * yzahl;
       schwellwert := bildpunkte div schwellwert;
end;

  { Bild nur mit schwarz und weiß darstellen }
Bitmap.PixelFormat := pf8Bit;
for y := 0 to Bitmap.height - 1 do
  begin
    PixelLine := Bitmap.ScanLine[y];

    for x := 0 to Bitmap.width - 1 do
    begin
       if PixelLine^[x] > schwellwert
       then begin
         pixelline^[x] := 255
           end
           else
         pixelline^[x] := 0;
         end;
    end;

  { Bildformat auf 1 Bit setzen, damit Speicher eingespart wird }
aBitmap.PixelFormat := pf1Bit;
for y := 0 to Bitmap.height - 1 do
  begin
    PixelLine := Bitmap.ScanLine[y];

    for x := 0 to Bitmap.width - 1 do
    begin
       if PixelLine^[x] = 255
       then begin
         pixelline^[x] := 1
           end
           else
         pixelline^[x] := 0;
         end;
    end;

 { Meldung ausgeben }
 OutputMessage('Es wurde ein Bild aufgenommen.');
 mainform.Label1.Caption := floattostr(bildpunkte);
 mainform.Label2.Caption := inttostr(schwellwert);
end;
  Mit Zitat antworten Zitat