Bild Scannen (Schwarz-Weiß) und alle Koordinaten der schwarzen Pixel in eine .ini schreiben

  • ja damit siehts so aus aber geht halt auch nich:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstants.au3>
    #include <GdiPlus.au3>
    #include <Misc.au3>
    #include <Color.au3>

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

    $file = FileOpenDialog("SnakeLvLEditor", @DesktopDir &"\Eigene Programme\Snake", "Bilder (*.jpg)")
    $iniFile = StringReplace($file, ".jpg", ".ini")

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

    _GDIPlus_Startup()

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

    $hBmp = _GDIPlus_ImageLoadFromFile($file)
    $PicWidth = _GDIPlus_ImageGetWidth($file)
    $PicHeight = _GDIPlus_ImageGetWidth($file)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) ; erstelle ein Bitmap aus Screenshot zur Verwendung mit GDI+
    _WinAPI_DeleteObject($hBmp) ; lösche Screenshot aus Speicher

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

    _GreyScale($hBitmap, 0, 0, $PicWidth, $PicHeight) ; Bereich wird in Graustufen umberechnet

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

    _GDIPlus_BitmapDispose($hBitmap) ; lösche Bild aus dem Speicher
    _GDIPlus_Shutdown()

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

    Func _GreyScale($hBitmap, $iX, $iY, $iW, $iH)
    Local $BitmapData = _GDIPlus_BitmapLockBits($hBitmap, $iX, $iY, $iW, $iH, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32RGB)
    Local $Stride = DllStructGetData($BitmapData, "Stride") ; Stride ist der Offset von einer Reihe zur nächsten
    Local $Width = DllStructGetData($BitmapData, "Width") ; Anzahl der Spalten
    Local $Height = DllStructGetData($BitmapData, "Height") ; Anzahl der Reihen
    Local $Scan0 = DllStructGetData($BitmapData, "Scan0") ; Die Bilddaten im Speicher
    Local $PixelData, $Color
    For $row = 0 To $Height - 1 ; Reihe für Reihe
    For $col = 0 To $Width - 1 ; Spalte für Spalte
    ; lese Farbinformation des aktuellen Pixels(Spalte,Reihe) aus
    $PixelData = DllStructCreate("dword", $Scan0 + ($row * $Stride) + ($col * 4))
    $Color = DllStructGetData($PixelData, 1)
    If $Color = 0 Then
    IniWrite($iniFile, "Pixel", $row, $col)
    EndIf
    Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $BitmapData)
    EndFunc ;==>_GreyScale

    [/autoit]
  • Zitat

    ja damit siehts so aus


    Nein tut es nicht.
    Es sieht so aus:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstants.au3>
    #include <GdiPlus.au3>
    #include <Misc.au3>
    #include <Color.au3>

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

    $file = FileOpenDialog("SnakeLvLEditor", @DesktopDir &"\Eigene Programme\Snake", "Bilder (*.jpg)")
    $iniFile = StringReplace($file, ".jpg", ".ini")

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

    _GDIPlus_Startup()

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

    $hBitmap = _GDIPlus_BitmapCreateFromFile($file)
    $height = _GDIPlus_ImageGetHeight($hBitmap)
    $width = _GDIPlus_ImageGetWidth($hBitmap)

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

    Local $BitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $width, $height, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    Local $Stride = DllStructGetData($BitmapData, "Stride") ; Stride ist der Offset von einer Reihe zur nächsten
    Local $Scan0 = DllStructGetData($BitmapData, "Scan0") ; Die Bilddaten im Speicher
    Local $PixelData
    For $row = 0 To $height - 1 ; Reihe für Reihe
    For $col = 0 To $width - 1 ; Spalte für Spalte
    ; lese Farbinformation des aktuellen Pixels(Spalte,Reihe) aus
    $PixelData = DllStructCreate("dword", $Scan0 + ($row * $Stride) + ($col * 4))
    $Color = DllStructGetData($PixelData, 1)
    If $Color = 0 Then
    IniWrite($iniFile, "Pixel", $row, $col)
    EndIf
    Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $BitmapData)

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

    _GDIPlus_Shutdown()
    MsgBox(0,"","fertig")

    [/autoit]


    Wo liegt das Problem?

  • geht immer noch nicht :D es schreibt einfach jedesmal in die ini:

    [Pixel]
    0=0

    und das wars :S

    EDIT: Ich hab den Fehler und weiß natürlich nix damit anzufangen... Der Rückgabewert für "Weiß" ist 4294967295 also nicht einheitlich 0 oder dezimal #000 oder hexadezimal #000000

    Einmal editiert, zuletzt von KingLoL (23. Oktober 2011 um 22:38)

  • Hab den funktionerenden Code:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstants.au3>
    #include <GdiPlus.au3>
    #include <Misc.au3>
    #include <Color.au3>

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

    $file = FileOpenDialog("Compiler", @DesktopDir &"\Eigene Programme\Snake", "Bilder (*.jpg)")
    If @error = 1 Then Exit
    $iniFile = StringReplace($file, ".jpg", ".ini")

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

    ProgressOn("Compiler","Compiliere...", "0%")
    _GDIPlus_Startup()

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

    $hBitmap = _GDIPlus_BitmapCreateFromFile($file)
    $height = _GDIPlus_ImageGetHeight($hBitmap)
    $width = _GDIPlus_ImageGetWidth($hBitmap)

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

    Local $BitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $width, $height, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    Local $Stride = DllStructGetData($BitmapData, "Stride") ; Stride ist der Offset von einer Reihe zur nächsten
    Local $Scan0 = DllStructGetData($BitmapData, "Scan0") ; Die Bilddaten im Speicher
    Local $PixelData
    For $row = 0 To $height - 1 ; Reihe für Reihe
    For $col = 0 To $width - 1 ; Spalte für Spalte
    $Percent = Round((100 / $height) * $row + (100 / $height) * (((100 / $width) * $col) / 100), 1)
    ProgressSet($Percent, $Percent &"%")
    ; lese Farbinformation des aktuellen Pixels(Spalte,Reihe) aus
    $PixelData = DllStructCreate("dword", $Scan0 + ($row * $Stride) + ($col * 4))
    $Color = DllStructGetData($PixelData, 1)
    $Color = _ColorGetRed($Color) + _ColorGetGreen($Color) + _ColorGetBlue($Color)
    If $Color = 0 Then
    IniWrite($iniFile, "Pixel", $row, $col)
    EndIf
    Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $BitmapData)

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

    _GDIPlus_Shutdown()
    ProgressOff()
    MsgBox(0,"Compiler","fertig")

    [/autoit]

    Einmal editiert, zuletzt von KingLoL (24. Oktober 2011 um 17:26)