Bilder aneinander reihen.

  • Hi

    Also ich hab da ein kleine Problem.
    Ich habe insgesamt 2145 Bilder mit dem Maß 256x256 Pixel im PNG Format.

    Nun muss ich diese Bilder aneinander reihen.
    Jeweils 65 Einzelbilder in eine Reihe und davon 33 Reihen.

    Das Endergebniss ist ein großes Bild mit den Maßen 16640x8448 Pixel.
    Das ganze mache ich mit Pain.NET (Dem Bildbearbeitungsprogramm.

    Nun wäre es verdammt mühsam, alle 2145 Einzelbilder von Hand
    in das Paint.NET einzfügen und bis aufs Pixel genau an zu ordnen.

    Deswegen will ich ein Programm dafür schreiben.

    Es soll also die Einzelbilder (am besten in einer For-Next schleife) in Paint.NET einfügen und automatisch an die richtige
    Position verschieben. Es muss aber wirklich aufs Pixel genau sein.

    Natürlich könnte ich eine Art Maus-script schreiben und die jeweiligen Positionen einfach ermitteln lassen,
    allerdings möchte ich es eher automatisiert haben.

    Hätte da evtl. jemand eine Idee, wie ich das realisieren könnte?

  • Hier, mit GDI+ :D.

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <File.au3>
    #include <Date.au3>

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

    $sPath_Src = @ScriptDir & "\Bilderordner" ;Ordner mit den Einzelbildern
    $sPath_Dst = @ScriptDir & "\New.png" ;Pfad für das fertige Gesamtbild

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

    $iWidthImage = 256 ;Breite der einzelnen Bilder
    $iHeightImage = 256 ;Höhe der einzelnen Bilder

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

    $iColumns = 65 ;Anzahl der Spalten
    $iRows = 33 ;Anzahl der Reihen

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

    _GDIPlus_Startup()

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

    $hBitmap = _GDIPlus_BitmapCreateFromScan0($iColumns * $iWidthImage, $iRows * $iHeightImage)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    $aFiles = _FileListToArray($sPath_Src, "*.png", 1)

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

    ProgressOn("Bilder zusammenfügen", "Fortschritt: 0%", "Bild 1 von " & $iColumns * $iRows & " - Verbleibende Zeit: 00:00:00", Default, Default, 18)
    Global $ElapsedTime = TimerInit(), $iH, $iM, $iS
    For $iY = 1 To $iRows
    For $iX = 1 To $iColumns
    If $iX * $iY > $aFiles[0] Then ExitLoop 2
    $hImageTmp = _GDIPlus_ImageLoadFromFile($sPath_Src & "\" & $aFiles[$iX * $iY])
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImageTmp, ($iX - 1) * $iWidthImage, ($iY - 1) * $iHeightImage, $iWidthImage, $iHeightImage)
    _GDIPlus_ImageDispose($hImageTmp)

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

    $iProgress = Ceiling($iX * $iY * 100 / ($iColumns * $iRows))
    $PPT = $iProgress / TimerDiff($ElapsedTime)
    _TicksToTime(Round(100 / $PPT - TimerDiff($ElapsedTime)), $iH, $iM, $iS)

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

    ProgressSet($iProgress, "Bild " & $iX * $iY & " von " & $iColumns * $iRows & " - Verbleibende Zeit: " & StringFormat("%02d:%02d:%02d", $iH, $iM, $iS), "Fortschritt: " & $iProgress)
    Next
    Next
    ProgressOff()

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

    _GDIPlus_ImageSaveToFile($hBitmap, $sPath_Dst)

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

    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_BitmapCreateFromScan0
    ; Description ...: Creates a Bitmap object based on an array of bytes along with size and format information
    ; Syntax.........: _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight[, $iStride = 0[, $iPixelFormat = 0x0026200A[, $pScan0 = 0]]])
    ; Parameters ....: $iWidth - The bitmap width, in pixels
    ; $iHeight - The bitmap height, in pixels
    ; $iStride - Integer that specifies the byte offset between the beginning of one scan line and the next. This
    ; +is usually (but not necessarily) the number of bytes in the pixel format (for example, 2 for 16 bits per pixel)
    ; +multiplied by the width of the bitmap. The value passed to this parameter must be a multiple of four
    ; $iPixelFormat - Specifies the format of the pixel data. Can be one of the following:
    ; |$GDIP_PXF01INDEXED - 1 bpp, indexed
    ; |$GDIP_PXF04INDEXED - 4 bpp, indexed
    ; |$GDIP_PXF08INDEXED - 8 bpp, indexed
    ; |$GDIP_PXF16GRAYSCALE - 16 bpp, grayscale
    ; |$GDIP_PXF16RGB555 - 16 bpp; 5 bits for each RGB
    ; |$GDIP_PXF16RGB565 - 16 bpp; 5 bits red, 6 bits green, and 5 bits blue
    ; |$GDIP_PXF16ARGB1555 - 16 bpp; 1 bit for alpha and 5 bits for each RGB component
    ; |$GDIP_PXF24RGB - 24 bpp; 8 bits for each RGB
    ; |$GDIP_PXF32RGB - 32 bpp; 8 bits for each RGB. No alpha.
    ; |$GDIP_PXF32ARGB - 32 bpp; 8 bits for each RGB and alpha
    ; |$GDIP_PXF32PARGB - 32 bpp; 8 bits for each RGB and alpha, pre-mulitiplied
    ; $pScan0 - Pointer to an array of bytes that contains the pixel data. The caller is responsible for
    ; +allocating and freeing the block of memory pointed to by this parameter.
    ; Return values .: Success - Returns a handle to a new Bitmap object
    ; Failure - 0 and either:
    ; |@error and @extended are set if DllCall failed
    ; |$GDIP_STATUS contains a non zero value specifying the error code
    ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources
    ; Related .......: _GDIPlus_ImageDispose
    ; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromScan0
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

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

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[6]
    EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

    [/autoit]
  • Es gibt seh gute Tutorials, auch hier im Forum, für GDI+. (Auch eins in einem anderen AutoIt Forum, Name sag ich mal nicht)
    Für deine Reihen würde ich ein 2-D Array anlegen,

    [autoit]

    Dim $aPics[65][33]

    [/autoit]

    Dann in einer For Schleife füllen auf die Graphic zeichnen. Das Bild wird dann jedoch sehr groß.

    Hierfür ein BSP aus dem Script Camerashot von AutoBert

    [autoit]

    $himg = _GDIPlus_ImageLoadFromFile($oFile)

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

    $hGraphics = _GDIPlus_ImageGetGraphicsContext($himg)
    $iX = _GDIPlus_ImageGetWidth($himg)
    $iy = _GDIPlus_ImageGetHeight($himg)
    $hBrush = _GDIPlus_BrushCreateSolid(); $Color)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 20, 2)
    $tLayout = _GDIPlus_RectFCreate($iX - 260, $iy - 30)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sInfo, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, $sInfo, $hFont, $aInfo[0], $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawImage($hGraphics, $himg, $iX, $iy)
    _GDIPlus_ImageSaveToFile($himg, $nFile)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_ImageDispose($himg)
    GUICtrlSetData($label1, $nr)
    FileDelete($oFile)

    [/autoit]

    Einige Sachen brauchst du nicht, die kannst du wegmachen.

    Für die Tutorials benutz bitte die Suchfunktion.

  • Danke für die Infos.

    name22: cooles script, leider blicke ich da net ganz durch.
    Es werden einige Fehler angezeigt:

    Spoiler anzeigen
    [autoit]

    >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Michael\Desktop\new.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams
    +>14:38:40 Starting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0407 Keyboard:00000407 OS:WIN_7/ CPU:X64 OS:X86)
    >Running AU3Check (1.54.19.0) from:C:\Program Files\AutoIt3
    C:\Users\Michael\Desktop\new.au3(32,39) : WARNING: $PPS: possibly used before declaration.
    _TicksToTime(Round(100 / $PPS -
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\Users\Michael\Desktop\new.au3(39,34) : ERROR: _GDIPlus_ImageSaveToFile() called with wrong number of args.
    _GDIPlus_ImageSaveToFile($hBitmap)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\Program Files\AutoIt3\Include\GDIPlus.au3(2374,51) : REF: definition of _GDIPlus_ImageSaveToFile().
    Func _GDIPlus_ImageSaveToFile($hImage, $sFileName)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\Users\Michael\Desktop\new.au3(32,39) : ERROR: $PPS: undeclared global variable.
    _TicksToTime(Round(100 / $PPS -
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\Users\Michael\Desktop\new.au3(16,91) : ERROR: _GDIPlus_BitmapCreateFromScan0(): undefined function.
    $hBitmap = _GDIPlus_BitmapCreateFromScan0($iColumns * $iWidthImage, $iRows * $iHeightImage)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\Users\Michael\Desktop\new.au3 - 3 error(s), 1 warning(s)
    !>14:38:40 AU3Check ended.rc:2
    >Exit code: 0 Time: 1.641

    [/autoit]