Hallo,
folgendes Problem:
Ich habe in einer Datei Stringangaben die auf eine GDI Grafik
gezeichnet werden müssen. Das klappt leider nicht.
Die Grafikdatei sollte ohne eine Gui zu öffnen direkt mit den Stringangaben gezeichnet werden.
Das ist die Textdatei (im Anhang)
Spoiler anzeigen
3|3|||||||||||||
Text 1|Arial|0|12.2449388504028|-96.2585067749023|200|60|0x03F66B98|0x03F66E60|65180408|65180720||||
Text 2|Arial|0|16.3265705108643|-20.7483043670654|77.5510158538818|20.408164024353|0x03E9ACD8|0x03F66E60|65641688|65350072||||
Text 3|Arial|0|83.6735076904297|14.6258459091187|77.551|20.408|0x03E9AD30|0x03F66E60|65359240|65350376||||
So ist die Stringdatei aufgebaut
[autoit]
;0=sText 1=sFont 2=iStyle 3=iX 4=iY 5=iW 6=iH 7=hFormat 8=hFamily 9=hPath 10=Brush
also alles was zum Zeichnen benötigt wird.
Diese Datei habe ich nun als 2DArray eingelesen
[autoit]
_FileReadToArray2D($sFile,$anewFile,"|")
Diese Daten sollten nun kpl. mit der Grafikdatei abgespeichert werden
Farben, Position ... ist alles enthalten.
_GDIPlus_ImageSaveToFile($h_Bitmap, @ScriptDir & "\Ilse.jpg")
Aber die Texte kommen da nie an....
Hier mal das kpl. Script
Spoiler anzeigen
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <File.au3>
#include <Array.au3>
Global $sFile = @ScriptDir & "\ilse.txt"
Global $anewFile
_FileReadToArray2D($sFile,$anewFile,"|")
[/autoit] [autoit][/autoit] [autoit]_arraydisplay($anewFile); Das sind die Font Daten...
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_Startup ()
;$h_Image = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Hunde.jpg")
$h_Image = _GDIPlus_ImageLoadFromFile (FileOpenDialog ('Bild auswählen', @ScriptDir, 'Bilder (*.jpg)'))
If Not $h_Image Then Exit _GDIPlus_Shutdown ()
$i_Width = _GDIPlus_ImageGetWidth ($h_Image)
$i_Height = _GDIPlus_ImageGetHeight ($h_Image)
$h_Gui = GUICreate ('', $i_Width, $i_Height + 20)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]$h_Graphics = _GDIPlus_GraphicsCreateFromHWND ($h_Gui)
$h_Bitmap = _GDIPlus_BitmapCreateFromGraphics ($i_Width, $i_Height, $h_Graphics)
$h_Buffer = _GDIPlus_ImageGetGraphicsContext ($h_Bitmap)
_WinAPI_RedrawWindow ($h_Gui, 0, 0, 0x0002)
GUIRegisterMsg (0x000F, 'WM_PAINT')
[/autoit] [autoit][/autoit] [autoit]OnAutoItExitRegister ('_OnExit')
GUISetState (@SW_SHOW, $h_Gui)
While True
Switch GUIGetMsg ()
Case $GUI_EVENT_CLOSE
Exit
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]EndSwitch
WEnd
;# Hier sollen die Strings auf das Bild gezeichnet werden!
Func WM_PAINT ()
_GDIPlus_GraphicsClear ($h_Buffer)
_GDIPlus_GraphicsDrawImageRect ($h_Buffer, $h_Image, 0, 0, $i_Width, $i_Height)
Local $hContext = _GDIPlus_ImageGetGraphicsContext($h_Bitmap)
[/autoit] [autoit][/autoit] [autoit]For $i = 1 To $anewFile[0][0] ; Hier werden die ganzen vorhandenen Strings gezeichnet
; So ist die Textdatei aufgebaut
;0=sText 1=sFont 2=iStyle 3=iX 4=iY 5=iW 6=iH 7=hFormat 8=hFamily 9=hPath 10=Brush
_GDIPlus_GraphicsDrawStringCustom ($h_Buffer, $anewFile[$i][0],$anewFile[$i][3],$anewFile[$i][4],$anewFile[$i][7],$anewFile[$i][7],$anewFile[$i][1])
Next
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_GraphicsDrawImageRect ($h_Graphics, $h_Bitmap, 0, 0, $i_Width, $i_Height)
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit]Func _OnExit ()
[/autoit] [autoit][/autoit] [autoit]WM_PAINT()
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_ImageSaveToFile($h_Bitmap, @ScriptDir & "\Ilse.jpg")
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_GraphicsDispose ($h_Graphics)
_GDIPlus_BitmapDispose ($h_Bitmap)
_GDIPlus_GraphicsDispose ($h_Buffer)
_GDIPlus_ImageDispose ($h_Image)
_GDIPlus_Shutdown ()
EndFunc
; #FUNCTION# ===================================================================
; Name ..........: _GDIPlus_GraphicsDrawStringCustom
; Description ...: Draw a customized string
; AutoIt Version : v3.3.6.1
; Syntax ........: _GDIPlus_GraphicsDrawStringCustom ($h_Graphics, $s_String, $n_X, $n_Y, $n_Size, $b_Color[, $i_Align = 0[, $i_Weight = 0[, $s_Font = 'Arial']]])
; Parameter(s): .: $h_Graphics - Handle to a Graphics object
; $s_String - String to be drawn
; $n_X - X coordinate where the string will be drawn
; $n_Y - Y coordinate where the string will be drawn
; $n_Size - Font size to use for drawing
; $b_Color - Alpha, Red, Green and Blue components
; $i_Align - The alignment can be one of the following:
; |0 - The text is aligned to the left
; |1 - The text is centered
; |2 - The text is aligned to the right
; $i_Weight - The style of the typeface. Can be a combination of the following:
; |0 - Normal weight or thickness of the typeface
; |1 - Bold typeface
; |2 - Italic typeface
; |4 - Underline
; |8 - Strikethrough
; $s_Font - Name of the Font Family
; Return Value ..: Success - True
; Failure - False
; Author(s) .....: $var
Func _GDIPlus_GraphicsDrawStringCustom ($h_Graphics, $s_String, $n_X, $n_Y, $n_Size, $b_Color, $i_Align = 0, $i_Weight = 0, $s_Font = 'Arial')
Local $a_CreateSolidFill, $a_CreateStringFormat, $a_CreateFontFamilyFromName, $a_CreateFont, $t_Struct, $p_Layout, $a_Return
$a_CreateSolidFill = DllCall ($ghGDIPDll, 'int', 'GdipCreateSolidFill', 'int', $b_Color, 'dword*', 0)
$a_CreateStringFormat = DllCall ($ghGDIPDll, 'int', 'GdipCreateStringFormat', 'int', 0, 'word', 0, 'ptr*', 0)
$a_CreateFontFamilyFromName = DllCall ($ghGDIPDll, 'int', 'GdipCreateFontFamilyFromName', 'wstr', $s_Font, 'ptr', 0, 'handle*', 0)
$a_CreateFont = DllCall ($ghGDIPDll, 'int', 'GdipCreateFont', 'handle', $a_CreateFontFamilyFromName[3], 'float', $n_Size, 'int', $i_Weight, 'int', 3, 'ptr*', 0)
$t_Struct = DllStructCreate ($tagGDIPRECTF)
$p_Layout = DllStructGetPtr ($t_Struct)
DllStructSetData ($t_Struct, 'X', $n_X)
DllStructSetData ($t_Struct, 'Y', $n_Y)
DllStructSetData ($t_Struct, 'Width', 0)
DllStructSetData ($t_Struct, 'Height', 0)
DllCall ($ghGDIPDll, 'int', 'GdipSetStringFormatAlign', 'handle', $a_CreateStringFormat[3], 'int', $i_Align)
$a_Return = DllCall ($ghGDIPDll, 'int', 'GdipDrawString', 'handle', $h_Graphics, 'wstr', $s_String, 'int', -1, 'handle', $a_CreateFont[5], _
'ptr', $p_Layout, 'handle', $a_CreateStringFormat[3], 'handle', $a_CreateSolidFill[2])
DllCall ($ghGDIPDll, 'int', 'GdipDeleteFont', 'handle', $a_CreateFont[5])
DllCall ($ghGDIPDll, 'int', 'GdipDeleteFontFamily', 'handle', $a_CreateFontFamilyFromName[3])
DllCall ($ghGDIPDll, 'int', 'GdipDeleteStringFormat', 'handle', $a_CreateStringFormat[3])
DllCall ($ghGDIPDll, 'int', 'GdipDeleteBrush', 'handle', $a_CreateSolidFill[2])
Return $a_Return[0] = 0
EndFunc ;==> _GDIPlus_GraphicsDrawStringCustom
;==========================================================================================================================================
; Function: _FileReadToArray2D($FILEPATH, $ARRAY [, $DELIM=-1])
;
; Description: Read 1D/2D array from file, if $DELIM is given (<> -1) 2D array will created
;
; Parameter(s): $FILEPATH - path/filename of the file to read in an array
; $ARRAY - array variable to hold readed data
; optional $DELIM - delimiter for 2D-array entries, default -1 (none 2D-array)
;
; Requirement(s): None
;
; Return Value(s): On Success - Returns -1
; On Failure - Returns 0 and sets @error = 1 (given file are not seperated with given delimiter or count of delimiters
; are not equal); @error = 2 (unable to open filepath)
;
; Note: If given file is delimited to create 2D-array ALL lines need the same count of delimiters, otherwise an error occurs!
;
; Author(s): BugFix ( [email='bugfix@autoit.de'][/email] )
;==========================================================================================================================================
Func _FileReadToArray2D($FILEPATH, ByRef $ARRAY, $DELIM=-1)
Local $fh = FileOpen($FILEPATH, 0), $line, $var, $n = 1
If $fh = -1 Then
SetError(2)
Return 0
EndIf
If $DELIM <> -1 Then
$line = FileReadLine($fh, 1)
$var = StringSplit($line, $DELIM)
If IsArray($var) Then
$Ubound2nd = $var[0]
Local $AR[1][$Ubound2nd]
$AR[0][0] = 0
Else
SetError(1)
Return 0
EndIf
While 1
$line = FileReadLine($fh, $n)
If @error = -1 Then ExitLoop
$var = StringSplit($line, $DELIM)
If IsArray($var) Then
ReDim $AR[UBound($AR)+1][$Ubound2nd]
For $i = 0 To $Ubound2nd-1
$AR[UBound($AR)-1][$i] = $var[$i+1]
Next
$AR[0][0] += 1
Else
SetError(1)
Return 0
EndIf
$n += 1
Wend
Else
Local $AR[1]
$AR[0] = 0
While 1
$line = FileReadLine($fh, $n)
If @error = -1 Then ExitLoop
ReDim $AR[UBound($AR)+1]
$AR[UBound($AR)-1] = $line
$AR[0] += 1
$n += 1
WEnd
EndIf
FileClose($fh)
$ARRAY = $AR
Return -1
EndFunc ;==>_FileReadToArray2D
Bin schon den ganzen Tag an diesem Problem,
ich hoffe ihr habt da ne Lösung.
Liebe Grüße
Ilse