Pixel eines Bildes auslesen ohne es darzustellen

  • Hallo Community,

    Ich brauche mal wieder eure Hilfe ;)
    Und zwar möchte ich einen bestimmten Pixel aus einem Bild auslesen ohne diese voher irgendwie mit GDI+ o.a. darzustellen. Also sowas wie PixelGetColor nur das man dann dort einen Pfad zu einem Bild angeben kann. In diesem Falle handelt es sich um ein PNG-Bild, wenn es aber auch lösungen für andere Formate gibt auch Posten!

    Danke im Vorraus

    mfg. Jam00

    Einmal editiert, zuletzt von Jam00 (13. Juli 2010 um 13:18)

  • Ja das habe ich mir schon gedacht, da ich diese Bild ausschließlich so auslesen möchte ist das Format eigentlich egal, welches währe denn zu empfelen? Ich bin gerade schon Dabei irgendeine Struktur in den Formaten zu finden und ordentlich am Googeln, habe aber noch nichts gefunden

    mfg. Jam00

  • Ne wenn ich es mit GDI+ mache ist das Bild ja imemr zu sehen, das ist nicht möglich. Müsste schon irgendwie so gehen. Bildbearbeitungsprogramme schaffen das doch auch. Naja ich suche mal im Englischen

    mfg. Jam00

  • Bei GDI+ muss das Bild nicht zu sehen sein.

    Spoiler anzeigen
    [autoit]

    Func _GetPixels(ByRef $aPixel, $hBitmap, $iX, $iY, $iW, $iH)
    Local $BitmapData = _GDIPlus_BitmapLockBits($hBitmap, $iX, $iY, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    Local $Stride = DllStructGetData($BitmapData, "Stride")
    Local $Width = DllStructGetData($BitmapData, "Width")
    Local $Height = DllStructGetData($BitmapData, "Height")
    Local $Scan0 = DllStructGetData($BitmapData, "Scan0")
    Local $PixelData
    For $row = 0 To $Height - 1 ; Reihe für Reihe
    For $col = 0 To $Width - 1 ; Spalte für Spalte
    $PixelData = DllStructCreate("dword", $Scan0 + ($row * $Stride) + ($col * 4))
    $aPixel[$col][$row] = Hex(DllStructGetData($PixelData, 1))
    Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $BitmapData)
    EndFunc ;==>_GetPixels

    [/autoit]
  • [autoit]

    Func _GDIPlus_GetPixel($hBitmap,$X,$Y)
    ; Prog@ndy
    Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapGetPixel", "ptr", $hBitmap, "int", $X, "int", $Y, "dword*", 0)
    If @error Then Return SetError(1,0,0)
    Return SetError($result[0],1,$result[4])
    EndFunc

    [/autoit]

    Damit musst du das Bild nicht anzeigen lassen, - nur mit _GDIPlus_ImageLoadFromFile einlesen.
    Den zurückgegebenen Handle als $hBitmap verwenden, feddisch ;)

    There are only 10 types of people in the world:
    Those who understand binary - and those who don't.

  • Wenn du in der Lage bist Bitmap-Dateien, vorzugsweise 32Bit, zu bearbeiten, gibt es eine sehr schnelle Variante den Pixel direkt aus der Datei auszulesen.
    Das BMP-Format ist sehr einfach s. Wikipedia. 54 Byte Header mit allen notwendigen Informationen, der Rest ist reine Pixelsuppe.
    Mühe wurde sich bereits an anderer Stelle gemacht...

    Spoiler anzeigen
    [autoit]

    #include <ScreenCapture.au3>
    #include-once

    [/autoit] [autoit][/autoit] [autoit]

    $file="test.bmp"
    _ScreenCapture_Capture($file,0,0,500,500)
    $t=timerinit()
    $hbmp=_BMPOpen($file)
    $col=_pixelread($hbmp,450,377)
    $m=timerdiff($t)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $m = ' & $m & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $col = ' & $col & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    shellexecute($file)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; ----------------------------------------------------------------------------
    ;
    ; AutoIt Version: 3.2.10.0
    ; Author: Evilertoaster <evilertoaster at yahoo dot com>
    ;
    ; Script Function:
    ; Basic BMP file managment.
    ;Script Version:
    ; 2.1
    ; ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    Func _BMPGetWidth(ByRef $BMPHandle)
    If IsArray($BMPHandle)=0 Then Return 0
    Return $BMPHandle[1]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _BMPGetHeight(ByRef $BMPHandle)
    If IsArray($BMPHandle)=0 Then Return 0
    Return $BMPHandle[2]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _BMPGetChecksum(ByRef $BMPHandle,$step=1)
    if not IsArray($BMPHandle) then Return -1
    $length=BinaryLen($BMPHandle[3])
    $a=1
    $b=0
    for $i=54 to $length
    $a=Mod($a+Dec(Hex(BinaryMid($BMPHandle[3],$i,1))),65521)
    $b=Mod($a+$b,65521)
    Next
    Return (BitShift(BitShift($b,-16),1)*2) + $a
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _PixelFill(ByRef $BMPHandle,$x,$y,$color,$variation=0)
    Local $CheckChart[UBound($BMPHandle,1)][UBound($BMPHandle,2)]
    Local $count=0
    $Tset=1
    Local $tracer[$Tset]
    $tracer[$tset-1]=$x&","&$y
    Local $CheckColor=Dec(_PixelRead($BMPHandle,$x,$y))
    $CheckChart[$y][$x]=1
    While 1
    if Abs(Dec(_PixelRead($BMPHandle,$x-1,$y))-$CheckColor)<=$variation Then
    $CheckChart[$x-1][$y]=1
    $count+=1
    _PixelWrite($BMPHandle,$x-1,$y,$color)
    $Tset+=1
    ReDim $tracer[$Tset]
    $tracer[$Tset-1]=$x&","&$y
    $x=$x-1
    ContinueLoop
    EndIf
    if Abs(Dec(_PixelRead($BMPHandle,$x,$y-1))-$CheckColor)<=$variation Then
    $CheckChart[$x][$y-1]=1
    $count+=1
    _PixelWrite($BMPHandle,$x,$y-1,$color)
    $Tset+=1
    ReDim $tracer[$Tset]
    $tracer[$Tset-1]=$x&","&$y
    $y=$y-1
    ContinueLoop
    EndIf
    if Abs(Dec(_PixelRead($BMPHandle,$x+1,$y))-$CheckColor)<=$variation Then
    $CheckChart[$x+1][$y]=1
    $count+=1
    _PixelWrite($BMPHandle,$x+1,$y,$color)
    $Tset+=1
    ReDim $tracer[$Tset]
    $tracer[$Tset-1]=$x&","&$y
    $x=$x+1
    ContinueLoop
    EndIf
    if Abs(Dec(_PixelRead($BMPHandle,$x,$y+1))-$CheckColor)<=$variation Then
    $CheckChart[$x][$y+1]=1
    $count+=1
    _PixelWrite($BMPHandle,$x,$y+1,$color)
    $Tset+=1
    ReDim $tracer[$Tset]
    $tracer[$Tset-1]=$x&","&$y
    $y=$y+1
    ContinueLoop
    EndIf
    $Point=StringSplit($tracer[$Tset-1],",")
    $x=$Point[1]
    $y=$Point[2]
    $Tset-=1
    ReDim $tracer[$Tset]
    if $tset=1 then ExitLoop
    Wend
    Return $count
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func _RectangleWrite(ByRef $BMPHandle,$x,$y,$Width,$Height,$color,$Thickness=1)
    if $Thickness<1 then Return 0
    if $Thickness>1 then
    Return SubRectangleWrite($BMPHandle,$x,$y,$Width,$Height,$color,$Thickness)
    EndIf
    Local $TempW=Round($Width/2)
    Local $TempH=Round($Height/2)
    _LineWrite($BMPHandle,$x-$TempW,$y-$TempH,$x+$TempW,$y-$TempH,$color)
    _LineWrite($BMPHandle,$x+$TempW,$y-$TempH,$x+$TempW,$y+$TempH,$color)
    _LineWrite($BMPHandle,$x+$TempW,$y+$TempH,$x-$TempW,$y+$TempH,$color)
    _LineWrite($BMPHandle,$x-$tempw,$y+$TempH,$x-$TempW,$y-$TempH,$color)
    Return $Width*$Height
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func SubRectangleWrite(ByRef $BMPHandle,$x,$y,$Width,$Height,$color,$Thickness)
    For $a=1 to $Thickness
    _RectangleWrite($BMPHandle,$x,$y,$Width-Round($a/2),$Height-Round($a/2),$color)
    _RectangleWrite($BMPHandle,$x,$y,$Width+Round($a/2),$Height+Round($a/2),$color)
    Next
    Return $Width*$Height
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func _EllipseWrite(ByRef $BMPHandle,$X,$Y,$Width,$Height,$color,$Thickness=1)
    if $Thickness<1 then Return 0
    if $Thickness>1 then
    Return SubEllipseWrite($BMPHandle,$x,$y,$Width,$Height,$color,$Thickness)
    EndIf
    Local $SumA=$Width/2
    Local $SumB=$Height/2
    Local $LastY=0
    Local $temp,$test,$h
    _PixelWrite($BMPHandle,Floor($x-$Width/2),$y,$color)
    _PixelWrite($BMPHandle,$x+$Width/2,$y,$color)
    For $a=-$Width/2 to $Width/2
    $temp=Sqrt(($SumB^2)*(1-(($a^2)/($SumA^2))))
    if $temp>$LastY then
    $test=$temp-$LastY
    Else
    $test=$LastY-$temp
    EndIf
    If $test<=1 then
    _PixelWrite($BMPHandle,$x+$a,$y+$temp,$color)
    _PixelWrite($BMPHandle,$x+$a,$y-$temp,$color)
    Else
    _LineWrite($BMPHandle,$x+$a-1,$y+$LastY,$x+$a,$y+$temp,$color)
    _LineWrite($BMPHandle,$x+$a-1,$y-$LastY,$x+$a,$y-$temp,$color)
    EndIf
    $LastY=$temp
    Next
    $h=(($sumA-$SumB)^2)/(($sumA+$SumB)^2)
    Return 3.14159*($SumA+$SumB)*(1+((3*$h)/(10+Sqrt(4-(3*$h)))))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func SubEllipseWrite(ByRef $BMPHandle,$x,$y,$Width,$Height,$color,$Thickness)
    for $a=1 to $Thickness
    _EllipseWrite($BMPHandle,$x,$y,$Width+$a,$Height+$a,$color)
    Local $Return=_EllipseWrite($BMPHandle,$x,$y,$Width-$a,$Height-$a,$color)
    Next
    Return $Return
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func SubLineWrite(ByRef $BMPHandle,$x1,$y1,$x2,$y2,$color,$loops)
    if $loops<1 then Return 0
    for $a=1 to $loops-1
    Local $Return=_LineWrite($BMPHandle,$x1+$a,$y1,$x2+$a,$y2,$color)
    _LineWrite($BMPHandle,$x1-$a,$y1,$x2-$a,$y2,$color)
    Next
    Return $Return
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _LineWrite(ByRef $BMPHandle,$x1,$y1,$x2,$y2,$color,$Thickness=1)
    If $Thickness<>1 then
    Local $Return=SubLineWrite($BMPHandle,$x1,$y1,$x2,$y2,$color,$Thickness)
    Return $Return
    EndIf
    If $x1=$x2 or $y1=$y2 Then
    if $x1=$x2 and $y1=$y2 then
    _PixelWrite($BMPHandle,$x1,$y1,$color)
    Return 1
    EndIf
    if $x1=$x2 then
    if $y1>$y2 Then
    Local $hold=$y1
    $y1=$y2
    $y2=$hold
    EndIf
    For $a=$y1 to $y2
    _PixelWrite($BMPHandle,$x1,$a,$color)
    Next
    Return $y2-$y1
    EndIf
    if $y1=$y2 Then
    If $x1>$x2 Then
    Local $hold=$x2
    $x2=$x1
    $x1=$hold
    EndIf
    for $a=$x1 to $x2
    _PixelWrite($BMPHandle,$a,$y1,$color)
    Next
    Return $x2-$x1
    EndIf
    EndIf
    If $x1>$x2 Then
    Local $hold=$x2
    $x2=$x1
    $x1=$hold
    $hold=$y1
    $y1=$y2
    $y2=$hold
    EndIf
    Local $slope=($y2-$y1)/($x2-$x1)
    if $y2>$y1 Then
    Local $highy=$y2
    Local $lowy=$y1
    Else
    Local $highy=$y1
    Local $lowy=$y2
    EndIf
    If $x2-$x1>$highy-$lowy Then
    Local $stepx=1
    Local $stepy=$slope
    Else
    Local $stepx=1/abs($slope)
    if $y1>$y2 then
    Local $stepy=-1
    Else
    Local $stepy=1
    EndIf
    EndIf
    Local $count=0
    for $a=$x1 to $x2 step $stepx
    _PixelWrite($BMPHandle,$a,$y1+($stepy*$count),$color)
    $count+=1
    Next
    Return Sqrt(($highy-$lowy)*($highy-$lowy)+($x2-$x1)*($x2-$x1))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _BMPCreate ($Width,$Height)
    Local $c=Mod($Width,4)
    Local $d=Binary("")
    if $c=3 then $d=Binary("0x000000")
    if $c=2 then $d=Binary("0x0000")
    if $c=1 then $d=Binary("0x00")
    ;***BMP header (54bytes total)***
    Local $Header=Binary("0x424D"& _ ;2bytes, BM signature
    "00000000"& _ ;4bytes, filesize (optional, omitted)
    "0000"& _ ;2bytes, reserved
    "0000"& _ ;2bytes, reserved
    "36000000"& _ ;4bytes, offset to image data
    "28000000"& _ ;4bytes, BITMAPINFOHEADER
    _Reverse8(Hex($Width,8))& _ ;4bytes, bitmap width
    _Reverse8(Hex($Height,8))& _ ;4bytes, bitmap hieght
    "0100"& _ ;2bytes, bitmap planes
    "1800"& _ ;2bytes, bitmap bitdepth
    "00000000"& _ ;4bytes, bitmap compression type (none)
    _Reverse8(Hex(($Height)* _
    ($Width)*3+($Height*$c),8))& _ ;4bytes, bitmap data size
    "00000000"& _ ;4bytes, bitmap horizontal resolution (optional,omitted)
    "00000000"& _ ;4bytes, bitmap vertical resolution (optional,omitted)
    "00000000"& _ ;4bytes, bitmap colors (optional?, omitted)
    "00000000") ;4bytes, important colors (optional?, omitted)
    ;***End Header***
    Local $rowData=Binary("")
    Local $imageData=Binary("")
    for $n=1 to $Width
    $rowData&=Binary("0xFFFFFF")
    Next
    $rowData&=$d
    for $m=1 to $Height
    $imageData&=$rowData
    Next
    Local $BMPHandle[4]
    $BMPHandle[0]=$c
    $BMPHandle[1]=$Width
    $BMPHandle[2]=$Height
    $BMPHandle[3]=$Header&$imageData
    Return $BMPHandle
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _BMPOpen($Path,$Progress=1)
    Local $Bpath=FileOpen($Path,16)
    If $Bpath=-1 then Return -1
    $AllOf=FileRead($Bpath)
    If BinaryMid($AllOf,1,2)<>"0x424D" then Return -2
    $x=Dec(_Reverse8(Hex(BinaryMid($AllOf,19,4))))
    $y=Dec(_Reverse8(Hex(BinaryMid($AllOf,23,4))))
    if $x=0 or $y=0 then Return -3
    for $c=$x to 0 step -4
    if $c<4 then ExitLoop
    Next
    Local $BMPHandle[4]
    $BMPHandle[0]=$c
    $BMPHandle[1]=$x
    $BMPHandle[2]=$y
    $BMPHandle[3]=$AllOf
    return $BMPHandle
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _PixelRead(ByRef $BMPHandle,$x,$y)
    If IsArray($BMPHandle)=False or $x>$BMPHandle[1]-1 Or $x<0 Or $y>$BMPHandle[2]-1 Or $y<0 Then Return 0
    $color = Hex(BinaryMid($BMPHandle[3],_ChordToOffset($x,$y,$BMPHandle),3))
    $color = _Reverse6($Color)
    Return $Color
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _PixelWrite(ByRef $BMPHandle,$x,$y,$color)
    If $x>$BMPHandle[1]-1 Or $x<0 Or $y>$BMPHandle[2]-1 Or $y<0 or StringLen($color)<>6 or Dec($Color)=0 Then Return 0
    $color = _Reverse6($Color)

    [/autoit] [autoit][/autoit] [autoit]

    $BMPHandle[3]=BinaryMid($BMPHandle[3],1,_ChordToOffset($x,$y,$BMPHandle))&Binary("0x"&$color)&BinaryMid($BMPHandle[3],_ChordToOffset($x,$y,$BMPHandle)+4)

    [/autoit] [autoit][/autoit] [autoit]

    Return 1
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ChordToOffset($x,$y,ByRef $BMPHandle)
    Local $row=($BMPHandle[1]*3+$BMPHandle[0])
    return 54+(($BMPHandle[2]*$row)-(($y+1)*$row)+($x*3))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _BMPWrite(ByRef $BMPHandle,$Fpath,$Progress=1)
    if IsArray($BMPHandle)=False then Return 0
    $out=FileOpen($Fpath,18)
    if $out=-1 then return -1
    FileWrite($out,$BMPHandle[3])
    FileClose($out)
    Return 1
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Reverse8($inHex)
    Return StringMid($inHex,7,2)&StringMid($inHex,5,2)&StringMid($inHex,3,2)&StringMid($inHex,1,2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Reverse6($inHex)
    Return StringMid($inHex,5,2)&StringMid($inHex,3,2)&StringMid($inHex,1,2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    wenn man es noch schneller und noch kürzer ohne die Funktionen haben möchte, bei 32Bpp einfach alles unwichtige rausschmeissen, dann wirds ein 3-Zeiler

  • Andy, limette, blubbstar
    Ich habe irgendwie als ein Problem beim Öffnen des Bildes, egal ob ich _GDIPlus_ImageLoadFromFile, _GDIPlus_BitmapCreateFromFile oder das aus der eine UDF nehme, immer gibt er mir einen Fehler bei öffnen des Bildes aus.

    Mein letzter Versuch
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_UseX64=n
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $hPic = _BMPOpen(@ScriptDir & "\bg_1.bmp")
    MsgBox (0,"",_GDIPlus_GetPixel ($hPic,1,1))

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_GetPixel($hBitmap,$X,$Y)
    ; Prog@ndy
    Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapGetPixel", "ptr", $hBitmap, "int", $X, "int", $Y, "dword*", 0)
    If @error Then Return SetError(1,0,0)
    Return SetError($result[0],1,$result[4])
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _BMPOpen($Path,$Progress=1)
    Local $Bpath=FileOpen($Path,16)
    If $Bpath=-1 then Return -1
    $AllOf=FileRead($Bpath)
    If BinaryMid($AllOf,1,2)<>"0x424D" then Return -2
    $x=Dec(_Reverse8(Hex(BinaryMid($AllOf,19,4))))
    $y=Dec(_Reverse8(Hex(BinaryMid($AllOf,23,4))))
    if $x=0 or $y=0 then Return -3
    for $c=$x to 0 step -4
    if $c<4 then ExitLoop
    Next
    Local $BMPHandle[4]
    $BMPHandle[0]=$c
    $BMPHandle[1]=$x
    $BMPHandle[2]=$y
    $BMPHandle[3]=$AllOf
    return $BMPHandle
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _PixelRead(ByRef $BMPHandle,$x,$y)
    If IsArray($BMPHandle)=False or $x>$BMPHandle[1]-1 Or $x<0 Or $y>$BMPHandle[2]-1 Or $y<0 Then Return 0
    $color = Hex(BinaryMid($BMPHandle[3],_ChordToOffset($x,$y,$BMPHandle),3))
    $color = _Reverse6($Color)
    Return $Color
    EndFunc
    Func _Reverse8($inHex)
    Return StringMid($inHex,7,2)&StringMid($inHex,5,2)&StringMid($inHex,3,2)&StringMid($inHex,1,2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Reverse6($inHex)
    Return StringMid($inHex,5,2)&StringMid($inHex,3,2)&StringMid($inHex,1,2)
    EndFunc
    Func _ChordToOffset($x,$y,ByRef $BMPHandle)
    Local $row=($BMPHandle[1]*3+$BMPHandle[0])
    return 54+(($BMPHandle[2]*$row)-(($y+1)*$row)+($x*3))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • hmmm, funktioniert bei mir einwandfrei mit deinem bild bg_1.bmp
    Btw, ist das Bild immer in diesen Abmessungen oder sind die Bilder auch größer/kleiner?

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    2 Mal editiert, zuletzt von Andy (4. Juli 2010 um 20:35)

  • Also ich weiß nicht genau, kann sein das es sich änder mal sehen
    Könntest du mal eine Exe kompelieren und hochladen, bei mir kommt immer 0 raus

    mfg. Jam00

    Einmal editiert, zuletzt von Jam00 (5. Juli 2010 um 12:20)

  • 640x482 x 8Bpp... die Scripte sind in dieser Form für 32Bpp, wenn du 8Bpp hast, musst du doch nur 1 Byte statt 4 auslesen...

    Fileopen binär, Daten lesen, 54 Byte BMP-Header vorne abschneiden, der Rest sind die Pixel, 1 Byte pro Pixel
    Hab gerade gesehen, 1024 Bytes Farbtabelle sind in deinem Bild auch noch drin....die also auch vorne abschneiden.
    Also ab Offset 1078 (54+1024) sind die Pixeldaten,
    Wenn du jetzt die Pixelfarbe von 77,88 haben willst, dann rechne 77+482x88=42493, dazu den Offset 1078 ergibt 43571. Dieses Byte hat die Farbe des Pixels

    [autoit]


    $bytes = FileRead("bg_1.bmp") ;alle Bytes lesen

    [/autoit][autoit][/autoit][autoit]

    Dim $array[480][640] ;array für alle pixel
    For $b = 0 To 639
    For $h = 0 To 479
    $array[$h][$b] = hex(asc(StringMid($bytes, $b + 482 * $h + 1078, 1)),2) ;farbe in hex
    Next
    Next

    [/autoit][autoit][/autoit][autoit]

    _arraydisplay($array)

    [/autoit]

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    2 Mal editiert, zuletzt von Andy (6. Juli 2010 um 16:26)

  • Aber was machen bei einem JPG ?

    Skript:

    Spoiler anzeigen
    [autoit]


    #include <Array.au3>
    #include <GDIPlus.au3>
    $test=_PixelGetColor(@ScriptDir&"\test.bmp")
    _ArrayDisplay($test)

    [/autoit] [autoit][/autoit] [autoit]

    Func _PixelGetColor($data)
    $data=FileGetLongName($data)
    $type=StringSplit($data,".")
    $type=$type[UBound($type)-1]
    Switch $type
    Case "bmp"
    $bytes = FileRead($data) ;alle Bytes lesen
    Dim $array[480][640] ;array für alle pixel
    For $b = 0 To 639
    For $h = 0 To 479
    $array[$h][$b] = hex(asc(StringMid($bytes, $b + 482 * $h + 1078, 1)),2) ;farbe in hex
    Next
    Next
    Case "jpg"
    ;Was kommt hier hin?
    EndSwitch
    Return $array
    EndFunc

    [/autoit]

    Nur keine Hektik - das Leben ist stressig genug

  • jpgs per _GDIPlus_BitmapCreateFromFile() öffnen,mit _GDIPlus_BitmapLockBits() die Bitmapdaten holen und auslesen. Dazu gibts aber sicher 20 Threads....auf der ersten Seite der Suche^^

  • Andy
    Super :)
    Woher weiß du immer den Dateiaufbau? Ich habs mit in Binär angeguck und dachte nur :?::?:

    EDIT:
    Irgendwas stimmt da aber noch nicht

    Spoiler anzeigen
    [autoit]

    $bytes = FileRead("bg_1.bmp") ;alle Bytes lesen

    [/autoit] [autoit][/autoit] [autoit]

    $array = hex(asc(StringMid($bytes, (300 + 482) * (1 + 1078), 1)),2) ;farbe in hex
    MsgBox (0,"",$array)

    [/autoit]

    Da gibt er mir 00 aus obwohl Pixel 300,1 weiß ist

    mfg. Jam00

    Einmal editiert, zuletzt von Jam00 (6. Juli 2010 um 17:53)

  • /EdIT/ Beitrag zerschossen....

    Bei Wikipedia gibts nen schönen Artikel zum Bitmap-Format. So gut wie alles, was intern in Windows abläuft, dreht sich um Bitmaps, alles andere sind nur verschiedene Dateiformate

    Deins:

    [autoit]

    $array = hex(asc(StringMid($bytes, (300 + 482) * (1 + 1078), 1)),2) ;farbe in hex

    [/autoit]


    Meins:

    [autoit]

    $array = hex(asc(StringMid($bytes, $b + 482 * $h + 1078, 1)),2) ;farbe in hex

    [/autoit]

    Fällt dir was auf...Grundschule, Punkt vor Strichrechnung...wenn man schon Klammern setzt, dann sollte man auch wissen, wo die Dinger hingehören ;)

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    Einmal editiert, zuletzt von Andy (6. Juli 2010 um 21:56)

  • Spoiler anzeigen
    [autoit]

    $bytes = FileRead("bg_1.bmp") ;alle Bytes lesen

    [/autoit] [autoit][/autoit] [autoit]

    $b = 1
    $h = 300
    $array = hex(asc(StringMid($bytes, $b + 482 * $h + 1078, 1)),2) ;farbe in hex
    MsgBox (0,"",$array)

    [/autoit]

    So geht es aber auch nicht

    mfg. Jam00