Bilder mit schwarzen Kreisen darstellen

  • Hallo @all,
    RapIt und ich haben heute mal die Idee gehabt, beliebige Bilder zu nehmen, und sie nur durch verschieden große, schwarze Kreise darzustellen.
    Das Ergebnis ist unserer Meinung nach sehr interessant geworden, da es nur schwarz/weiß ist:
    [Blockierte Grafik: http://dl.dropbox.com/u/24291173/monalisa.bmp][Blockierte Grafik: http://dl.dropbox.com/u/24291173/monalisa_low.bmp][Blockierte Grafik: http://dl.dropbox.com/u/24291173/monalisa_mid.bmp][Blockierte Grafik: http://dl.dropbox.com/u/24291173/monalisa_high.bmp][Blockierte Grafik: http://dl.dropbox.com/u/24291173/monalisa_veryhigh.bmp]

    [Blockierte Grafik: http://dl.dropbox.com/u/24291173/auge.bmp][Blockierte Grafik: http://dl.dropbox.com/u/24291173/auge_new2.bmp]

    Man kann zwischen verschieden Präzisionen wählen,
    aber probiert es selbst aus!

    Code
    [autoit]

    #include <GDIPlus.au3>
    #include <GuiConstants.au3>
    #include <GDIP.au3>
    #include <ComboConstants.au3>
    #include <WindowsConstants.au3>

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

    Global $hBitmap, $Precision = 5, $hBrush, $hGraphic, $hBitmap2, $hBuffer
    _GDIPlus_Startup()

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

    $hGui = GUICreate("Bild-Wandler", 400, 100, 192, 124)
    $hLoad = GUICtrlCreateButton("Lade Bild", 0, 0, 100, 50)
    $hConvert = GUICtrlCreateButton("Konvertiere", 100, 0, 100, 50)
    $hSave = GUICtrlCreateButton("Speichern", 200, 0, 100, 50)
    GUICtrlCreateLabel("Präzision:", 300, 0, 100, 25)
    $hCombo = GuiCtrlCreateCombo("Mittel", 300, 25, 100, 25, $CBS_DROPDOWNLIST)
    GuiCtrlSetData(-1, "Niedrig|Genau|Sehr Genau")
    $hProgress = GuiCtrlCreateProgress(0, 50, 400, 50)
    GUISetState(@SW_SHOW)

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

    GuiCtrlSetState($hConvert, $GUI_DISABLE)
    GuiCtrlSetState($hSave, $GUI_DISABLE)
    $hGui2 = GuiCreate("Anzeige", 100, 100, -1, -1, $WS_BORDER, -1, $hGui)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)

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

    While 1
    $nMsg = GuiGetMsg($hGui)
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap2)
    _GDIPlus_BrushDispose($hBrush)
    Exit
    Case $hLoad
    $sOpen = FileOpenDialog("Wähle Bild", @ScriptDir, "Bild (*.bmp)")
    $hBitmap = _GDIPlus_BitmapCreateFromFile($sOpen)
    GuiCtrlSetState($hSave, $GUI_DISABLE)
    If $hBitmap = 0 Then
    MsgBox(0, "Fehler", "Fehler beim Laden des Bilds")
    GuiCtrlSetState($hConvert, $GUI_DISABLE)
    Else
    $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
    WinMove("Anzeige", "", Default, Default, $iWidth, $iHeight)
    GuiSetState(@SW_SHOW, $hGui2)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui2)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    GuiCtrlSetState($hConvert, $GUI_ENABLE)
    EndIf
    Case $hConvert
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    $hBitmap2 = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap2)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
    GuiCtrlSetstate($hProgress, 0)
    Switch GuiCtrlRead($hCombo)
    Case "Niedrig"
    $Precision = 18
    Case "Mittel"
    $Precision = 12
    Case "Genau"
    $Precision = 8
    Case "Sehr Genau"
    $Precision = 5
    EndSwitch
    For $i = 0 to $iWidth/$Precision - 1
    For $j = 0 to $iHeight/$Precision - 1
    $Grey = _GetGrey($i * $Precision, $j * $Precision, $Precision, $Precision)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $i * $Precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), $j * $precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), (255 - $Grey) / (255 / $Precision), (255 - $Grey) / (255 / $Precision), $hBrush)
    Next
    GuiCtrlSetData($hProgress, ($i+1) * 100 / ($iWidth/$Precision))
    Next
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap2, 0, 0, $iWidth, $iHeight)
    GuiCtrlSetData($hProgress, 100)
    GuiCtrlSetState($hSave, $GUI_ENABLE)
    Case $hSave
    $sSave = FileSaveDialog("Speichern", @ScriptDir, "Bild (*.bmp)")
    If Not $sSave = "" Then
    If StringRight($sSave, 4) <> ".bmp" Then $sSave &= ".bmp"
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap2, 0, 0, $iWidth, $iHeight)
    If _GDIPlus_ImageSaveToFile($hBitmap2, $sSave) Then
    MsgBox(0, "Speichern", "Erfolgreich gespeichert!")
    Else
    MsgBox(0, "Speichern", "Speichern fehlgeschlagen!")
    Endif
    EndIf
    EndSwitch
    WEnd

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

    Func _GetGrey($iX, $iY, $Width, $Height)
    Local $PixCol, $Count = 0
    For $i = $iX to $Width + $iX - 1
    For $j = $iY to $Height + $iY - 1
    $PixCol = StringTrimLeft(Hex(_GDIPlus_BitmapGetPixel($hBitmap, $i, $j)), 2)
    $Count += Dec(StringLeft($PixCol, 2)) + Dec(StringMid($PixCol, 3, 2)) + Dec(StringRight($PixCol, 2))
    Next
    Next
    Return $Count / ($Width*$Height) / 3
    EndFunc

    [/autoit]


    Die GDIP.au3 wird benötigt!

    Weitere Beispiele und der Source im Anhang!

    Viel Spaß damit,
    RapIt&Fresapore

  • Nette Idee! :thumbup:

    Übrigens: das nennt sich Halftone bzw. auf Deutsch Druckraster: -> http://de.wikipedia.org/wiki/Druckraster

    Appropos Halftone (lag bei mir so rum):

    Spoiler anzeigen
    [autoit]


    #AutoIt3Wrapper_Compile_both=y
    #AutoIt3Wrapper_Run_Obfuscator=y
    #Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
    #AutoIt3Wrapper_UseUpx=y
    #AutoIt3Wrapper_UPX_Parameters=--brute --crp-ms=999999 --all-methods --all-filters
    #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
    #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>

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

    Opt("GuiOnEventMode", 1)

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

    Global Const $width = @DesktopWidth * 0.25
    Global Const $height = @DesktopHeight * 0.25
    Global Const $GUI_title = "GDI+ Halftone by UEZ 2011"
    Global Const $hGui = GUICreate($GUI_title, $width, $height)

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

    _GDIPlus_Startup()
    Global $hBMP = _WinAPI_CreateBitmap($width, $height)
    Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    Global $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    Global $hDC = _WinAPI_GetDC($hGUI)
    Global $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC)
    Global $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBITMAP)
    Global $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer)
    Global Const $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    Global Const $hBrush_Clear = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    GUISetState()

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

    Global $i, $t, $tt, $x, $y, $ii, $distx, $disty, $d, $r
    Global Const $SRCCOPY = 0x00CC0020
    Global Const $circles = 3
    Global $s = 16 ;spacing between dots
    Global $aCircles[$circles][5] ; x, y, dx, dy, m

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

    For $i = 0 To UBound($aCircles) - 1
    $aCircles[$i][0] = Random(0, 1) ;x -> x position
    $aCircles[$i][1] = Random(0, 1) ;y -> y position
    $aCircles[$i][2] = Random(0, 1) * 0.03 ;dx -> speed x vector
    $aCircles[$i][3] = Random(0, 1) * 0.03 ;dy -> speed y vector
    $aCircles[$i][4] = Random(0.08, 0.25) ;m -> mass
    Next

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

    GUISetOnEvent(-3, "_Exit")

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

    Global $fps = 0
    AdlibRegister("FPS", 1000)

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

    Do
    _WinAPI_BitBlt($hDC, 0, 0, $width, $height, $hDC_backbuffer, 0, 0, $SRCCOPY)
    ;~ $t = TimerInit()
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $width, $height, $hBrush_Clear)
    For $i = 0 To $circles - 1 ;move mass centers
    $aCircles[$i][0] += $aCircles[$i][2]
    $aCircles[$i][1] += $aCircles[$i][3]
    If $aCircles[$i][0] > 1 Or $aCircles[$i][0] < 0 Then $aCircles[$i][2] *= -1
    If $aCircles[$i][1] > 1 Or $aCircles[$i][1] < 0 Then $aCircles[$i][3] *= -1
    Next
    For $x = 0 To $width Step $s
    For $y = 0 To $height Step $s
    $ii = 0.2 ;intensity in this dot
    For $i = 0 To $circles - 1 ;sum influence from all mass centers
    $distx = $x - $aCircles[$i][0] * $width ;x distance
    $disty = $y - $aCircles[$i][1] * $height ;y distance
    $d = Sqrt($distx * $distx + $disty * $disty) / ($height + $width) ;dance between current mass center and current dot
    If Not $d Then ;add influence from current mass center (but not too much!)
    $ii += 2
    Else
    $ii += Min($aCircles[$i][4] / ($d * $d * 20), 2)
    EndIf
    Next
    $r = Min($ii, $s) * $s * 0.70
    _GDIPlus_GraphicsFillEllipse($hGraphic, $x + 1, $y + 1, $r, $r, $hBrush)
    Next
    Next
    ;~ $tt = TimerDiff($t)
    ;~ If $tt < 24 Then ;if the time was too short, half the spacing between dots
    ;~ $s /= 2
    ;~ ElseIf $tt > 74 Then ;if the time was too long, increase spacing by 8 pixels
    ;~ $s += 8
    ;~ EndIf
    $fps += 1
    Until Not Sleep(30)

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

    Func FPS()
    WinSetTitle($hGui, "", $GUI_title & " / FPS: " & $fps)
    $fps = 0
    EndFunc ;==>FPS

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

    Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
    EndFunc ;==>Min

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

    Func _Exit()
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush_Clear)
    _WinAPI_SelectObject($hDC_backbuffer, $DC_obj)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_BitmapDispose($hBitmap)
    _WinAPI_DeleteObject($hHBITMAP)
    _WinAPI_ReleaseDC($hGUI, $hDC)
    _GDIPlus_Shutdown()
    GUIDelete($hGui)
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Ist echt genial geworden!! Respekt!! Sowas ähnliches hab ich gestern auch angefangen gehabt jedoch mit Rechtecken und Farben. :thumbup:

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake

  • Hallo nochmal!

    Ich habe gerade noch eingebaut, dass man zwischen verschiedenen Farben sowie zwischen Quadrat oder Kreis wählen kann. Das war im Prinzip nur eine winzige Änderung, aber wen es interessiert:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GuiConstants.au3>
    #include <GDIP.au3>
    #include <ComboConstants.au3>
    #include <WindowsConstants.au3>
    #Include <GuiComboBox.au3>

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

    Global $hBitmap, $Precision = 5, $hBrush, $hGraphic, $hBitmap2, $hBuffer, $Color,$Form

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

    _GDIPlus_Startup()

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

    $hGui = GUICreate("Bild-Wandler", 600, 100, 192, 124)
    $hLoad = GUICtrlCreateButton("Lade Bild", 0, 0, 100, 50)
    $hConvert = GUICtrlCreateButton("Konvertiere", 100, 0, 100, 50)
    $hSave = GUICtrlCreateButton("Speichern", 200, 0, 100, 50)

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

    GUICtrlCreateLabel("Präzision:", 300, 0, 100, 25)
    $hPrecCombo = GuiCtrlCreateCombo("Mittel", 300, 25, 100, 25, $CBS_DROPDOWNLIST)
    GuiCtrlSetData(-1, "Niedrig|Genau|Sehr Genau")
    Global $ComboPrecData[4] = [12,18,8,5]

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

    GUICtrlCreateLabel("Form:", 400, 0, 100, 25)
    $hFormCombo = GuiCtrlCreateCombo("Kreis", 400, 25, 100, 25, $CBS_DROPDOWNLIST)
    GuiCtrlSetData(-1, "Quadrat")

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

    GUICtrlCreateLabel("Farbe:", 500, 0, 100, 25)
    $hColorCombo = GuiCtrlCreateCombo("Schwarz", 500, 25, 100, 25, $CBS_DROPDOWNLIST)
    GuiCtrlSetData(-1, "Blau|Grün|Rot|Gelb")
    Global $ComboColorData[5] = [0xFF000000,0xFF0000FF,0xFF00FF00,0xFFFF0000,0xFFFFFF00]

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

    $hProgress = GuiCtrlCreateProgress(0, 50, 600, 50)
    GUISetState(@SW_SHOW)

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

    GuiCtrlSetState($hConvert, $GUI_DISABLE)
    GuiCtrlSetState($hSave, $GUI_DISABLE)
    $hGui2 = GuiCreate("Anzeige", 100, 100, -1, -1, $WS_BORDER, -1, $hGui)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)

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

    While 1
    $nMsg = GuiGetMsg($hGui)
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap2)
    _GDIPlus_BrushDispose($hBrush)
    Exit
    Case $hLoad
    $sOpen = FileOpenDialog("Wähle Bild", @ScriptDir, "Bild (*.bmp)")
    $hBitmap = _GDIPlus_BitmapCreateFromFile($sOpen)
    GuiCtrlSetState($hSave, $GUI_DISABLE)
    If $hBitmap = 0 Then
    MsgBox(0, "Fehler", "Fehler beim Laden des Bilds")
    GuiCtrlSetState($hConvert, $GUI_DISABLE)
    Else
    $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
    WinMove("Anzeige", "", Default, Default, $iWidth, $iHeight)
    GuiSetState(@SW_SHOW, $hGui2)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui2)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    GuiCtrlSetState($hConvert, $GUI_ENABLE)
    EndIf
    Case $hConvert
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    $hBitmap2 = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap2)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
    GuiCtrlSetstate($hProgress, 0)
    $Precision = $ComboPrecData[_GUICtrlComboBox_GetCurSel($hPrecCombo)]
    _GDIPlus_BrushSetSolidColor($hBrush,$ComboColorData[_GUICtrlComboBox_GetCurSel($hColorCombo)])
    $Form = _GUICtrlComboBox_GetCurSel($hFormCombo)

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

    For $i = 0 to $iWidth/$Precision - 1
    For $j = 0 to $iHeight/$Precision - 1
    _Draw($Form,_GetGrey($i * $Precision, $j * $Precision, $Precision, $Precision))
    Next
    GuiCtrlSetData($hProgress, ($i+1) * 100 / ($iWidth/$Precision))
    Next
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap2, 0, 0, $iWidth, $iHeight)
    GuiCtrlSetData($hProgress, 100)
    GuiCtrlSetState($hSave, $GUI_ENABLE)
    Case $hSave
    $sSave = FileSaveDialog("Speichern", @ScriptDir, "Bild (*.bmp)")
    If Not $sSave = "" Then
    If StringRight($sSave, 4) <> ".bmp" Then $sSave &= ".bmp"
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap2, 0, 0, $iWidth, $iHeight)
    If _GDIPlus_ImageSaveToFile($hBitmap2, $sSave) Then
    MsgBox(0, "Speichern", "Erfolgreich gespeichert!")
    Else
    MsgBox(0, "Speichern", "Speichern fehlgeschlagen!")
    Endif
    EndIf
    EndSwitch
    WEnd

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

    Func _GetGrey($iX, $iY, $Width, $Height)
    Local $PixCol, $Count = 0
    For $i = $iX to $Width + $iX - 1
    For $j = $iY to $Height + $iY - 1
    $PixCol = StringTrimLeft(Hex(_GDIPlus_BitmapGetPixel($hBitmap, $i, $j)), 2)
    $Count += Dec(StringLeft($PixCol, 2)) + Dec(StringMid($PixCol, 3, 2)) + Dec(StringRight($PixCol, 2))
    Next
    Next
    Return $Count / ($Width*$Height) / 3
    EndFunc

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

    Func _Draw($Form,$Grey)
    Switch $Form
    Case 0
    _GDIPlus_GraphicsFillEllipse($hBuffer, $i * $Precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), $j * $precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), (255 - $Grey) / (255 / $Precision), (255 - $Grey) / (255 / $Precision), $hBrush)
    Case 1
    _GDIPlus_GraphicsFillRect($hBuffer, $i * $Precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), $j * $precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), (255 - $Grey) / (255 / $Precision), (255 - $Grey) / (255 / $Precision), $hBrush)
    EndSwitch
    EndFunc

    [/autoit]

    Ich finde aber, dass es mit schwarzen Kreisen immer noch am Besten aussieht, da bekommt man halt eher einen Eindruck von richtigen "Grautönen" obwohl es ja nur die unterschiedliche Größe der Kreise ist...

    RapIt

  • Hi,
    hier dann auf Wunsch ;) noch eine Variante, in der der User als "Form" auch einen Buchstaben oder ein ASCII Zeichen benutzen kann! Ich find das zwar nicht so schön, aber es war keine große Veränderung und außerdem ist es lustig, ein Bild mit beliebigen Zeichen darzustellen!

    Die neue Version:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GuiConstants.au3>
    #include <GDIP.au3>
    #include <ComboConstants.au3>
    #include <WindowsConstants.au3>
    #Include <GuiComboBox.au3>

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

    Global $hBitmap, $Precision = 5, $hBrush, $hGraphic, $hBitmap2, $hBuffer, $Color,$Form,$Char,$hFont

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

    _GDIPlus_Startup()

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

    $hGui = GUICreate("Bild-Wandler", 600, 100, 192, 124)
    $hLoad = GUICtrlCreateButton("Lade Bild", 0, 0, 100, 50)
    $hConvert = GUICtrlCreateButton("Konvertiere", 100, 0, 100, 50)
    $hSave = GUICtrlCreateButton("Speichern", 200, 0, 100, 50)

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

    GUICtrlCreateLabel("Präzision:", 300, 0, 100, 25)
    $hPrecCombo = GuiCtrlCreateCombo("Mittel", 300, 25, 100, 25, $CBS_DROPDOWNLIST)
    GuiCtrlSetData(-1, "Niedrig|Genau|Sehr Genau")
    Global $ComboPrecData[4] = [12,18,8,5]

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

    GUICtrlCreateLabel("Form:", 400, 0, 100, 25)
    $hFormCombo = GuiCtrlCreateCombo("Kreis", 400, 25, 100, 25, $CBS_DROPDOWNLIST)
    GuiCtrlSetData(-1, "Quadrat|Eigener Buchstabe|ASCII")
    Global $hFormat = _GDIPlus_StringFormatCreate ()
    Global $hFamily = _GDIPlus_FontFamilyCreate ("Arial")

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

    GUICtrlCreateLabel("Farbe:", 500, 0, 100, 25)
    $hColorCombo = GuiCtrlCreateCombo("Schwarz", 500, 25, 100, 25, $CBS_DROPDOWNLIST)
    GuiCtrlSetData(-1, "Blau|Grün|Rot|Gelb")
    Global $ComboColorData[5] = [0xFF000000,0xFF0000FF,0xFF00FF00,0xFFFF0000,0xFFFFFF00]

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

    $hProgress = GuiCtrlCreateProgress(0, 50, 600, 50)
    GUISetState(@SW_SHOW)

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

    GuiCtrlSetState($hConvert, $GUI_DISABLE)
    GuiCtrlSetState($hSave, $GUI_DISABLE)
    $hGui2 = GuiCreate("Anzeige", 100, 100, -1, -1, $WS_BORDER, -1, $hGui)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)

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

    While 1
    $nMsg = GuiGetMsg($hGui)
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap2)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    Exit
    Case $hLoad
    $sOpen = FileOpenDialog("Wähle Bild", @ScriptDir, "Bild (*.bmp)")
    $hBitmap = _GDIPlus_BitmapCreateFromFile($sOpen)
    GuiCtrlSetState($hSave, $GUI_DISABLE)
    If $hBitmap = 0 Then
    MsgBox(0, "Fehler", "Fehler beim Laden des Bilds")
    GuiCtrlSetState($hConvert, $GUI_DISABLE)
    Else
    $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
    WinMove("Anzeige", "", Default, Default, $iWidth, $iHeight)
    GuiSetState(@SW_SHOW, $hGui2)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui2)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    GuiCtrlSetState($hConvert, $GUI_ENABLE)
    EndIf
    Case $hConvert
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    $hBitmap2 = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap2)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
    GuiCtrlSetstate($hProgress, 0)
    $Precision = $ComboPrecData[_GUICtrlComboBox_GetCurSel($hPrecCombo)]
    _GDIPlus_BrushSetSolidColor($hBrush,$ComboColorData[_GUICtrlComboBox_GetCurSel($hColorCombo)])
    $Form = _GUICtrlComboBox_GetCurSel($hFormCombo)
    If $Form = 2 Then
    $Char = StringLeft(InputBox("Eigener Buchstabe","Bitte geben Sie einen Buchstaben ein!"),1)
    ElseIf $Form = 3 Then
    $Char = Chr(InputBox("ASCII","Bitte geben Sie einen ASCII Code zwischen 0 und 255 ein!"))
    EndIf
    For $i = 0 to $iWidth/$Precision - 1
    For $j = 0 to $iHeight/$Precision - 1
    _Draw($Form,_GetGrey($i * $Precision, $j * $Precision, $Precision, $Precision))
    Next
    GuiCtrlSetData($hProgress, ($i+1) * 100 / ($iWidth/$Precision))
    Next
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap2, 0, 0, $iWidth, $iHeight)
    GuiCtrlSetData($hProgress, 100)
    GuiCtrlSetState($hSave, $GUI_ENABLE)
    Case $hSave
    $sSave = FileSaveDialog("Speichern", @ScriptDir, "Bild (*.bmp)")
    If Not $sSave = "" Then
    If StringRight($sSave, 4) <> ".bmp" Then $sSave &= ".bmp"
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap2, 0, 0, $iWidth, $iHeight)
    If _GDIPlus_ImageSaveToFile($hBitmap2, $sSave) Then
    MsgBox(0, "Speichern", "Erfolgreich gespeichert!")
    Else
    MsgBox(0, "Speichern", "Speichern fehlgeschlagen!")
    Endif
    EndIf
    EndSwitch
    WEnd

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

    Func _GetGrey($iX, $iY, $Width, $Height)
    Local $PixCol, $Count = 0
    For $i = $iX to $Width + $iX - 1
    For $j = $iY to $Height + $iY - 1
    $PixCol = StringTrimLeft(Hex(_GDIPlus_BitmapGetPixel($hBitmap, $i, $j)), 2)
    $Count += Dec(StringLeft($PixCol, 2)) + Dec(StringMid($PixCol, 3, 2)) + Dec(StringRight($PixCol, 2))
    Next
    Next
    Return $Count / ($Width*$Height) / 3
    EndFunc

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

    Func _Draw($Form,$Grey)
    Switch $Form
    Case 0
    _GDIPlus_GraphicsFillEllipse($hBuffer, $i * $Precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), $j * $precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), (255 - $Grey) / (255 / $Precision), (255 - $Grey) / (255 / $Precision), $hBrush)
    Case 1
    _GDIPlus_GraphicsFillRect($hBuffer, $i * $Precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), $j * $precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), (255 - $Grey) / (255 / $Precision), (255 - $Grey) / (255 / $Precision), $hBrush)
    Case 2 or 3
    $hFont = _GDIPlus_FontCreate ($hFamily,(255 - $Grey) / (255 / $Precision), 0,2)
    $tLayout = _GDIPlus_RectFCreate ($i * $Precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), $j * $precision + 0.5 * ($precision - ((255 - $Grey) / (255 / $Precision))), (255 - $Grey) / (255 / $Precision), (255 - $Grey) / (255 / $Precision))
    _GDIPlus_GraphicsDrawStringEx ($hBuffer, $Char, $hFont, $tLayout, $hFormat, $hBrush)
    EndSwitch
    EndFunc

    [/autoit]
  • Hey,
    schön, dass es dir gefällt. :)

    nur ein paar mehr Datei Formate müsste es unterstützen


    Das ist ja eigentlich kein Problem, solange die Formate von GdiPlus unterstützt werden...
    Im Anhang noch eine Version, die jpg, png und bmp unterstützt. Ich habs nur einmal ausprobiert, sollte aber gehen...

    Viele Grüße,
    RapIt