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
#include <GDIPlus.au3>
#include <GuiConstants.au3>
#include <GDIP.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
Global $hBitmap, $Precision = 5, $hBrush, $hGraphic, $hBitmap2, $hBuffer
_GDIPlus_Startup()
$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)
GuiCtrlSetState($hConvert, $GUI_DISABLE)
GuiCtrlSetState($hSave, $GUI_DISABLE)
$hGui2 = GuiCreate("Anzeige", 100, 100, -1, -1, $WS_BORDER, -1, $hGui)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
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
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
Die GDIP.au3 wird benötigt!
Weitere Beispiele und der Source im Anhang!
Viel Spaß damit,
RapIt&Fresapore