Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi if routine für getpixel (brett vorm kopf) (https://www.delphipraxis.net/158232-if-routine-fuer-getpixel-brett-vorm-kopf.html)

rhodan 10. Feb 2011 00:22

if routine für getpixel (brett vorm kopf)
 
hallöchen community

die panels haben von anfang an ne weisse farbe.
mal angenommen das foto was ich auf farbanteile durchsuche hat an der vorgegebenen Pixelposition keinen blau oder grünanteil, und somit ändert sich die panelfarbe auch nicht.

wie schreibe ich nun ne IF routine das wenn die panelfarbe nach dem prüfen immernoch weiss ist, an pixelposition X+1,Y+1 gesucht wird, bzw anstatt der 506 meinetwegen ne 508?

Code:
begin
  DWord(AColor) := GetPixel(dc,506,554);
 
 //Blauanteil eines Fotos
  if (AColor[1] > 220) and (AColor[2] > 95) and (AColor[3] > 190) then
    panel1.color :=clBLUE;

  //Grünanteil eines fotos
  if (AColor[1] > 190) and (AColor[2] < 50) and (AColor[3] < 50) then
    panel2.color :=clGREEN;

if panel1.color := clwhite then... ??!

danke.

Sir Rufo 10. Feb 2011 00:29

AW: if routine für getpixel (brett vorm kopf)
 
Suchst evtl. eine Schleife?
Delphi-Quellcode:
var
  x, y : integer;

x := 1;
y:= 1;
while panel1.Color = clWhite do
  begin
    ...
    Inc( x ); Inc( y ); // im 45 Grad Winkel durch das Bild
  end;

rhodan 10. Feb 2011 00:33

AW: if routine für getpixel (brett vorm kopf)
 
im prinzip schon...allerdings wollte ich nicht die ganzen farbsuchroutinen wieder runterschreiben sondern dachte ich könnte einfach die koordinaten oberhalb der suchroutinen ändern, so das automatisch nach den farben in der neuen koordinate gesucht wird....denn sonst wird der code ingesamt 10 mal so groß, wenn ich für jede koordinate noch 2 alternative angebe samt farbschemata :S

Sir Rufo 10. Feb 2011 00:40

AW: if routine für getpixel (brett vorm kopf)
 
:wiejetzt:

Eine Schleife ist dafür da einen Codeteil mehrmals zu durchlaufen, damit man den eben NICHT x-mal tippen muss.

rhodan 10. Feb 2011 01:04

AW: if routine für getpixel (brett vorm kopf)
 
i see :-)

hab das hier jetzt ausprobiert, allerdings hängt er sich mehr oder weniger auf, ziel war eigentlich das er nach jedem durchlauf X um 1 erhöht wenn die farbe nicht gefunden wurde.

Code:
var
x:integer;

...
x:=0;

  while panel1.Color = clwhite do
 begin
 DWord(AColor) := GetPixel(dc,506+x,554);
 
 //Blauanteil eines Fotos
  if (AColor[1] > 220) and (AColor[2] > 95) and (AColor[3] > 190) then
    panel1.color :=clBLUE;

  //Grünanteil eines fotos
  if (AColor[1] > 190) and (AColor[2] < 50) and (AColor[3] < 50) then
    panel2.color :=clGREEN;

 x:= +1;
   end;
ne idee?

Blup 10. Feb 2011 07:17

AW: if routine für getpixel (brett vorm kopf)
 
Delphi-Quellcode:
x := x + 1;
Aber dann sollte es eine zusätzliche Abbruchbedingung geben.

Vieleicht besser so:
Delphi-Quellcode:
for x := {xMin} to {xMax} do
begin
  if {TestFarbe1} then
  begin
    panel1.color := clBLUE;
    Break;
  end;
  if {TestFarbe2} then
  begin
    panel1.color := clGREEN;
    Break;
  end;
end;

rhodan 10. Feb 2011 23:03

AW: if routine für getpixel (brett vorm kopf)
 
Zitat:

Zitat von Blup (Beitrag 1080752)
Delphi-Quellcode:
x := x + 1;

ahhh...das war der fehler! ihr seid die besten! vielen dank :-D
kaum macht man es richtig, schon funktionierts ;-)


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:37 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