Antwort auf: Farbe eines Pixels feststellen

Startseite Foren Deutsches LiveCode-Forum Farbe eines Pixels feststellen Antwort auf: Farbe eines Pixels feststellen

#14067
Torsten
Teilnehmer

    Habs gefunden, ist leider kein direkter Befehl, sondern man muss ein bisschen arbeiten:

    Beispiel-Stack: http://forums.livecode.com/viewtopic.php?t=17655

    Der Weg: in der imageData eines Images sind die Pixelinfos sortiert nach der Position von links oben nach rechts unten. ImageData ist eine lange Reihe von Bytes. Jedes Pixel braucht 4 Byte für seine Farbangabe, d.h. man muss immer diese Sprünge machen:

    Code:

    
       put the imageData of image "meinBild.jpg" into tData
       put the width of image "meinBild.jpg" into tWidth
       put the height of image "meinBild.jpg" into tHeight
       
       ask "put the column and row of the pixel whose RGB value you want"
       
       put item 1 of it  into tColumn
       put item 2 of it - 1 into tRow
       
       put tWidth * tRow * 4 into tAllRows
       put tColumn * 4 into tTheColumns
       put tAllRows + tTheColumns into tByte -- for loc 1,1 it gives byte 4, see above how the 4 bytes of the pixel work
          
          -- we want byte 2 to 4 of the pixel
       put charToNum (char tByte - 2 of tData) into tRed -- byte 
       put charToNum (char tByte - 1 of tData) into tGreen
       put charToNum (char tByte of tData) into tBlue
       put tRed & comma & tGreen & comma & tBlue into tWholeRGB
       
       answer "the RGB value of pixel " & tColumn  & "," & tRow +1 & " is" & cr  & cr & tWholeRGB
    

    Ich mach daraus mal eine Funktion und poste den Code hier in den Strang.

    Beste Grüße
    Torsten