AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi [gelöst] Problem mit RGB und ScanLine
Thema durchsuchen
Ansicht
Themen-Optionen

[gelöst] Problem mit RGB und ScanLine

Ein Thema von Thanatos81 · begonnen am 26. Feb 2007 · letzter Beitrag vom 26. Feb 2007
 
Thanatos81
(Gast)

n/a Beiträge
 
#1

[gelöst] Problem mit RGB und ScanLine

  Alt 26. Feb 2007, 10:04
So, erst mal etwas Code vorweg und dann die Erklärung meines Problems anhand des Codes.

Einlesen des Bildes und Zerlegung in RGB-Werte
Delphi-Quellcode:
  
  imgOri.Picture.Bitmap.Assign(bmp);

  imgRed.Picture.Bitmap.Height := bmp.Height;
  imgRed.Picture.Bitmap.Width := bmp.Width;

  // imgBlue.Picture.Bitmap.Height := bmp.Height;
  // imgBlue.Picture.Bitmap.Width := bmp.Width;

  // imgGreen.Picture.Bitmap.Height := bmp.Height;
  // imgGreen.Picture.Bitmap.Width := bmp.Width;

    //ToDo: Für Release komplett betrachten
  for y := 0 to 170 do //bmp.Height - 1 do
  begin
    line := bmp.ScanLine[y];
    for x := 0 to bmp.Width do
    begin
      if (line^.rgbtBlue < 200) and (line^.rgbtGreen < 200) then
      begin
        temp := line^.rgbtRed;
        imgRed.Picture.Bitmap.Canvas.Pixels[x, y] := RGB2TColor(temp, 0, 0);

        // temp := line^.rgbtGreen;
        // imgGreen.Picture.Bitmap.Canvas.Pixels[x, y] := RGB2TColor(0, temp, 0);

        // temp := line^.rgbtBlue;
        // imgBlue.Picture.Bitmap.Canvas.Pixels[x, y] := RGB2TColor(0, 0, temp);
      end;
      inc(line);
    end;
  end;
  deleteBrightPixel(imgRed.Picture.Bitmap);
  // deleteBrightPixel(imgGreen.Picture.Bitmap);
  // deleteBrightPixel(imgBlue.Picture.Bitmap);
Prozedur deleteBrightPixel
Delphi-Quellcode:
procedure deleteBrightPixel(bmp: TBitmap);
var
  tut: Cardinal;
  count: Cardinal;
  x, y: Integer;
  hue, lumi, sat: Word;
  c: TColor;
  r, g, b: Byte;
  line: PRGBTriple;
begin
  tut := 0;
  count := 0;

  for y := 0 to bmp.Height - 1 do
  begin
    line := bmp.ScanLine[y];
    for x := 0 to bmp.Width - 1 do
    begin
      c := bmp.Canvas.Pixels[x, y];

      if c <> clWhite then
      begin
        TColor2RGB(c, r, g, b);
        if (x = 139) and (y = 112) then
          showMessage(format('%d, %d, %d', [line^.rgbtRed, line^.rgbtGreen
            , line^.rgbtBlue]));

        ColorRGBToHLS(ColorToRGB(c), hue, lumi, sat);

        inc(tut, lumi);
        inc(count);
      end;
      inc(line);
    end;
  end;

  tut := tut div count;

  for y := 0 to bmp.Height - 1 do
  begin
    for x := 0 to bmp.Width - 1 do
    begin
      c := bmp.Canvas.Pixels[x, y];
      if c <> clWhite then
      begin
        TColor2RGB(c, r, g, b);
        ColorRGBToHLS(ColorToRGB(c), hue, lumi, sat);

        if (lumi > tut) then
          bmp.Canvas.Pixels[x, y] := clWhite;
      end;
    end;
  end;
end;
So, das ganze funktioniert soweit auch so, wie ich es mir vorstelle. Nur wollte ich jetzt auch das Löschen heller Pixel mittels ScanLine beschleunigen. Komischerweise gibt mir ScanLine aber bei Aufruf der Prozedur mit imgRed.Picture.Bitmap bei der if-Bedingung nur einen Wert für Grün an, obwohl das Bild nur noch aus Weiß/Rot besteht, und weiß wird ja mittels "if c <> clWhite" abgewiesen. Die gewählten X/Y-Koordinaten beinhalten einen dunkelroten Punkt.

Und ich frage mich jetzt, ob ich was Grundlegendes mit ScanLine verkehrt mache, oder warum angeblich nur ein Grünanteil vorhanden ist.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:21 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz