Hallo Leute,
Ich versuche einen Icon-Editor zu machen. Den größten Teil habe ich noch es fehlen wie man sieht noch die Palette und das Laden. Mein Problem leig erstmal beim speichern/benutzen. Wo das Problem liegt sieht man beim Kommentar bei _GDIPlus_BitmapCloneArea().
Mein Code
#notrayicon
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIplus.au3>
#include <Misc.au3>
global $title="Iconsetter V0.1 by TheShadowAE"
global $farben=2
#Region ### START Koda GUI section ### Form=D:\Progen\AutoIt\Meine\Forms\Iconsetter.kxf
$Form1 = GUICreate($title, 448, 321, 192, 124)
$Button1 = GUICtrlCreateButton("Laden", 332, 8, 97, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Speichern", 332, 48, 97, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Speichern als", 332, 88, 97, 25, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Beenden", 332, 284, 105, 25, $WS_GROUP)
$Button5 = GUICtrlCreateButton("Farbpalette", 332, 128, 97, 25, $WS_GROUP)
$Button6 = GUICtrlCreateButton("Bild leeren", 332, 168, 97, 25, $WS_GROUP)
$akt=guictrlcreatelabel("",447,320)
GUISetState(@SW_SHOW)
$Form2=guicreate("Saver",32,32)
#EndRegion ### END Koda GUI section ###
_GDIPlus_Startup()
dim $pen[$farben]
$pen[0]=_GDIPlus_BrushCreateSolid(0xFF000000)
$pen[1]=_GDIPlus_BrushCreateSolid(0xFFFFFFFF)
global $gra=_GDIPlus_GraphicsCreateFromHWND($Form1)
global $buffer=_GDIPlus_BitmapCreateFromGraphics(300,300,$gra)
global $backgra=_GDIPlus_ImageGetGraphicsContext($buffer)
global $file=""
global $activepen=1
Dim $feld[32][32]
global $gra2=_GDIPlus_GraphicsCreateFromHWND($Form2)
global $buffer2=_GDIPlus_BitmapCreateFromGraphics(32,32,$gra2)
global $backgra2=_GDIPlus_ImageGetGraphicsContext($buffer2)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE,"ende",$Form1)
guictrlsetonevent($Button4,"ende")
guictrlsetonevent($Button1,"load")
guictrlsetonevent($Button2,"save")
guictrlsetonevent($Button3,"saveas")
guictrlsetonevent($Button5,"palette")
guictrlsetonevent($Button6,"clean")
GUIRegisterMsg(0x000F, "Redraw_GUI")
start()
While not _IsPressed("1B")
if _ispressed("1") Then
if xmouse()>=0 and xmouse()<=320 and ymouse()>=0 and ymouse()<=320 Then
;~ msgbox(0,xmouse()/10,ymouse()/10)
$feld[round(xmouse()/11)][round(ymouse()/11)]=$activepen
EndIf
elseif _ispressed("2") Then
if xmouse()>=0 and xmouse()<=320 and ymouse()>=0 and ymouse()<=320 Then
;~ msgbox(0,floor(xmouse()/10),floor(ymouse()/10))
$feld[round(xmouse()/11)][round(ymouse()/11)]=2
EndIf
EndIf
if WinActive($title)=0 Then winwaitactive($title)
sleep(50)
WEnd
Func ende()
adlibunregister("redraw")
for $x=0 to $farben-1
_GDIPlus_BrushDispose($pen[$x])
Next
_GDIPlus_GraphicsDispose($gra)
_GDIPlus_BitmapDispose($buffer)
_GDIPlus_GraphicsDispose($backgra)
_GDIPlus_GraphicsDispose($gra2)
_GDIPlus_BitmapDispose($buffer2)
_GDIPlus_GraphicsDispose($backgra2)
_GDIPlus_Shutdown()
Exit
EndFunc
func start()
_GDIPlus_GraphicsClear($backgra,0xFFFFFFFF)
;~ _GDIPlus_GraphicsDrawLine($backgra,1,1,300,300,$pen[0])
_GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,320,320)
adlibregister("redraw",100)
$activepen=1
EndFunc
Func Redraw_GUI($hWnd, $msg, $wParam, $lParam)
_WinAPI_RedrawWindow($hWnd, "", "", $RDW_UPDATENOW + $RDW_FRAME)
_GDIPlus_GraphicsClear($backgra,0xFFFFFFFF)
for $x=0 to 31
for $y=0 to 31
if $feld[$x][$y]<>0 then _GDIPlus_GraphicsFillRect($backgra,$x*10,$y*10,10,10,$pen[$feld[$x][$y]-1])
Next
Next
_GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,320,320)
EndFunc
Func redraw()
guictrlsetdata($akt,"")
EndFunc
func load()
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit]func save()
$mybuff=drawtobuffer()
if $file<>"" Then
$sCLSID = _GDIPlus_EncodersGetCLSID ("BMP")
_GDIPlus_ImageSaveToFileEx($mybuff, $file, $sCLSID)
Else
$file=FileSaveDialog("Speichern unter...", @ScriptDir, "Icons (*.ico)",16,"MyIcon.ico")
$sCLSID = _GDIPlus_EncodersGetCLSID ("BMP")
_GDIPlus_ImageSaveToFileEx($mybuff, $file, $sCLSID)
EndIf
_GDIPlus_ImageDispose($mybuff)
EndFunc
func saveas()
$mybuff=drawtobuffer()
$file=FileSaveDialog("Speichern unter...", @ScriptDir, "Icons (*.ico)",16,"MyIcon.ico")
$sCLSID = _GDIPlus_EncodersGetCLSID ("BMP")
_GDIPlus_ImageSaveToFileEx($mybuff, $file, $sCLSID)
_GDIPlus_ImageDispose($mybuff)
EndFunc
func xmouse()
$pos=MouseGetPos()
$win=WinGetPos($title)
$x=$pos[0]-$win[0]-3
return $x
EndFunc
func ymouse()
$pos=MouseGetPos()
$win=WinGetPos($title)
$y=$pos[1]-$win[1]-28
return $y
EndFunc
func palette()
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit]func drawtobuffer()
for $x=0 to 31
for $y=0 to 31
if $feld[$x][$y]<>0 then
_GDIPlus_GraphicsFillRect($backgra2,$x,$y,1,1,$pen[$feld[$x][$y]-1])
Else
_GDIPlus_GraphicsFillRect($backgra2,$x,$y,1,1,$pen[1])
endif
Next
Next
_GDIPlus_GraphicsDrawImageRect($gra2,$buffer2,0,0,32,32)
$mybuff=_GDIPlus_BitmapCloneArea($buffer2,0,0,32,32,$GDIP_PXF08INDEXED);gibt 0x00000000 zurück. bei $mybuff=$buffer2 und dispose weg beim saven ist es kein gültiges icon
return $mybuff
EndFunc
func clean()
for $x=0 to 31
for $y=0 to 31
$feld[$x][$y]=0
Next
Next
EndFunc