Hallo liebe User,
nach dem Wälzen mehrerer Threads komme ich leider nicht weiter: Ich möchte zunächst Text auf Bilder schreiben. Und zwar auf alle innerhalb des bestimmten Ordners:
[autoit]Global $FileSearch = FileFindFirstFile(@ScriptDir & "\source\*.jpg")
If $FileSearch = -1 Then Exit
Local $file
While 1
$file = FileFindNextFile($FileSearch)
If @error Then ExitLoop
_Losung_Bild($file)
WEnd
Dabei handelt es sich um 5 Strings (in verschiedenen Schriftarten), die auf die Images "aufgedruckt" werden sollen. Danach soll das Bild abgespeichert werden. Das Resultat dient mir dann als Desktop-Wallpaper.
Die von UEZ vorgeschlagene, von mir minimal angepasste Version (bitte Bilderpfade anpassen) findet ihr hier:
Spoiler anzeigen
; Quelle: UEZ
#include <GDIPlus.au3>
_GDIPlus_Startup()
Local $hBild = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\source\img001.jpg")
Local $iX = _GDIPlus_ImageGetWidth($hBild)
Local $iY = _GDIPlus_ImageGetHeight($hBild)
Local $text = "Beispieltext"
[/autoit] [autoit][/autoit] [autoit]Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iX, $iY)
Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Local $hPinsel = _GDIPlus_BrushCreateSolid (0xFFFFFFFF)
Local $hFormat = _GDIPlus_StringFormatCreate ()
Local $hFamily = _GDIPlus_FontFamilyCreate ("English")
Local $font_size = Floor(($iX - StringLen($text)) / 20)
Local $hFont = _GDIPlus_FontCreate ($hFamily, $font_size, 0)
Local $tLayout = _GDIPlus_RectFCreate (0, 0, 0, 0)
Local $aInfo = _GDIPlus_GraphicsMeasureString ($hContext, $text, $hFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawImageRect($hContext, $hBild, 0, 0, $iX, $iY)
[/autoit] [autoit][/autoit] [autoit]Local $fWidth = DllStructGetData($aInfo[0], "Width")
Local $fHeight = DllStructGetData($aInfo[0], "Height")
DllStructSetData($tLayout, "x", $iX / 2 - Round($fWidth / 2, 0))
DllStructSetData($tLayout, "y", $iY / 2 - Round($fHeight / 2, 0) - 2)
_GDIPlus_GraphicsDrawStringEx ($hContext, $text, $hFont, $tLayout, $hFormat, $hPinsel)
[/autoit] [autoit][/autoit] [autoit]_Exit()
[/autoit] [autoit][/autoit] [autoit]Func _Exit()
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\ready\img001.jpg")
_GDIPlus_ImageDispose($hBild)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hPinsel)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_Shutdown()
Exit
EndFunc
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)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[6]
EndFunc
Diese ist auch sehr aufschlussreich, und es funktioniert wunderbar. Aber ich möchte die Strings bestimmt positionieren: Alle sollen (übereinander angeordnet) in der unteren, rechten Bildecke erscheinen. Dieses aber mit einem gewissen Abstand von unten (da die Taskbar im Weg ist). Deshalb müssen sie meiner Meinung nach rechtsbündig ausgerichtet werden.
Darüber hinaus würde ich gerne die ursprünglich weiße Schrift schwarz umranden, damit man auch auf hellen Wallpapers die Schrift erkennt. Absolut scharf wäre ja wohl zusätzlich noch die Erkennung der unteren Ecke, ob sie etwa zu hell ist und schwarz als Schriftfarbe nicht besser angebracht wäre, wahrscheinlich über PixelGet.... Das übersteigt aber mein können (weil es punktuell nicht reicht, wäre doof, wenn ich den einzigen hellen Pixel erwische) und stößt wieder Diskussionen an...
Viele Grüße und bereits im Voraus herzlichen Dank für Hilfe in jeglicher Hinsicht,
Matthias