Icon-editor

  • 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
    [autoit]

    #notrayicon
    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIplus.au3>
    #include <Misc.au3>

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

    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 ###

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

    _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)

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

    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()

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

    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

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

    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

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

    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

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

    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

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

    Func redraw()
    guictrlsetdata($akt,"")
    EndFunc

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

    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

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

    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

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

    func xmouse()
    $pos=MouseGetPos()
    $win=WinGetPos($title)
    $x=$pos[0]-$win[0]-3
    return $x
    EndFunc

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

    func ymouse()
    $pos=MouseGetPos()
    $win=WinGetPos($title)
    $y=$pos[1]-$win[1]-28
    return $y
    EndFunc

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

    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

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

    func clean()
    for $x=0 to 31
    for $y=0 to 31
    $feld[$x][$y]=0
    Next
    Next
    EndFunc

    [/autoit]

    2 Mal editiert, zuletzt von TheShadowAE (16. Februar 2010 um 19:54)

  • Bitte in [autoit;][;/autoit] und nicht in Quellcode packen (du müsstest das doch eig. wissen)
    und bitte Zeilenangabe hinzufügen ;)

    mfg Ubuntu

  • hallo,

    also ich benutze icoFX, wenn ich mal ein icon selbst bzw., aus png dateien erstellen will!

    gruß gmmg

    Er möchte einen Icon-Editor selber scripten.

  • das ist mir schon klar ;)

    war ja auch keine kritik, sonst hätte ich erst garnicht geantwortet ... :!:

    sollte nur eine anregung sein, wie ein editor mit den verschiedenen menüpunkten aussehen kann.
    es gibtja viele icon editoren, die taugen aber einfach nichts ...

    zurück zum thema ... 8o
    werden die verschiedenen anzeigegrößen auch implementiert?

    gruß gmmg

    Einmal editiert, zuletzt von gmmg (17. Februar 2010 um 15:49)