Jump to content

an image converter


logmein
 Share

Recommended Posts

this is my second program

#include <GUIConstants.au3>
#include <WIndowsCOnstants.au3>
#include <GUIListView.au3>
#include <ButtonConstants.au3>
#Include <GuiComboBox.au3>
#include <GuiConstantsEx.au3>
#Include <GuiComboBoxEx.au3>
#include <GDIPlus.au3>
#include <File.au3>
_GDIPlus_Startup ()
Opt ('WinTitleMatchMode',2)
HotKeySet ('^r','_remove')
Dim $title = 'Image Converter'
Dim $x = 'All supported formats (*.JPG;*.JPEG;*.JIB;*.JPC;*.JP2;*.JFIF;*.JIF;*.JPE;*.JNG;*.BMP;*.DIB;*.TIF;*.TIFF;*.PNG;*.GIFF;*.


GIF;*.PCX;*.PCD;*.PCC;*.TGA;*.ICO)'
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Welcome\Desktop\Image Tools\imageconverter.kxf
$Form = GUICreate($title, 493, 421, -1, -1)
$savepath = GUICtrlCreateInput("", 56, 8, 391, 21)
$Label1 = GUICtrlCreateLabel("Save to :", 0, 8, 47, 18)
$saveb = GUICtrlCreateButton("...", 448, 7, 43, 23, 0)
$list = GUICtrlCreateListView("Name|Type|Dimensions|Size|Convert to", 1, 56, 490, 358)
GUICtrlSendMsg(-1, 0x101E, 0, 350)
GUICtrlSendMsg(-1, 0x101E, 1, 50)
GUICtrlSendMsg(-1, 0x101E, 2, 80)
GUICtrlSendMsg(-1, 0x101E, 3, 60)
GUICtrlSendMsg(-1, 0x101E, 4, 80)
$add = GUICtrlCreateButton("&Add", 0, 31, 75, 25, 0)
$remove = GUICtrlCreateButton("Remove", 76, 31, 75, 25, 0)
$combo1 = GUICtrlCreateCombo("", 154, 32, 154, 25)
GUICtrlSetData (-1,'JPG|JPEG|JIB|JPC|JP2|JFIF|JIF|JPE|JNG|BMP|DIB|TIF|TIFF|PNG|GIFF|GIF|PCX|PCD|PCC|TGA|ICO')
$convert = GUICtrlCreateButton("&Convert", 310, 31, 92,25)
GUICtrlSetCursor (-1, 0)
$preview = GUICtrlCreateButton ('&Preview',403,31,90,25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Welcome\Desktop\Image Tools\add.kxf
$addform = GUICreate("Add Image", 400, 210, -1, -1, BitOR($WS_MINIMIZEBOX,$WS_CAPTION,$WS_POPUP,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE),$Form)
$Group1 = GUICtrlCreateGroup("", 0, 0, 390, 180)
$radio1 = GUICtrlCreateLabel("&Add from computer", 9, 16, 113, 17)
GUICtrlSetState (-1,$GUI_CHECKED)
$Label1 = GUICtrlCreateLabel("Image path (mutiple images seperate by ';')", 9, 40, 208, 18)
$path1 = GUICtrlCreateInput("", 9, 64, 321, 22)
$bpath1 = GUICtrlCreateButton("...", 330, 63, 27, 25, 0)
$expand1 = GUICtrlCreateButton("<>", 357, 63, 27, 25, 0)
$Radio2 = GUICtrlCreateLabel("A&dd from Internet", 9, 96, 113, 17)
$Label2 = GUICtrlCreateLabel("Image URL (mutiple images seperate by ';')", 9, 120, 207, 18)
$path2 = GUICtrlCreateInput("", 9, 144, 345, 22)
$expand2 = GUICtrlCreateButton("<>", 355, 143, 27, 25, 0)
;$Label3 = GUICtrlCreateLabel("Convert to :", 9, 176, 60, 18)
;$combo2 = GUICtrlCreateCombo("Combo1", 73, 176, 145, 25)
;GUICtrlSetData(-1, "JPG|JPEG|JFIF")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ok = GUICtrlCreateButton("&Add", 8, 183, 75, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$cancel = GUICtrlCreateButton("&Cancel", 88, 183, 75, 25, 0)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $add
            GUISetState (@SW_SHOW,$addform)
        Case $cancel
            _cancel ()
        Case $bpath1
            $bpathgui = FileOpenDialog ('Browse for image',@DesktopDir,$x,1+4,'',$addform)
            IF Not @error Then
                $Split1 = StringSplit ($bpathgui,'|')
                If not @error Then
                for $i = 2 to $Split1[0]
                    GUICtrlSetData ($path1,GUICtrlRead ($path1) & ';' & $Split1[1] & '\' & $Split1[$i])
                Next
            Else
                GUICtrlSetData ($path1,GUICtrlRead ($path1) & ';' & $bpathgui)
            EndIf
            
                If StringLeft (GUICtrlRead ($path1),1) = ';' Then
                    GUICtrlSetData ($path1,StringTrimLeft(GUICtrlRead($path1),1))
                EndIf
                If Stringright (GUICtrlRead ($path1),1) = ';' Then
                    GUICtrlSetData ($path1,StringTrimRight(GUICtrlRead($path1),1))
                EndIf
            EndIf
        Case $expand1
            ShellExecute ('notepad.exe')
            if WinWaitActive ('Notepad') then
                
                ControlSetText ('Notepad','','Edit1',StringReplace (guictrlread ($path1),';',@CRLF))
                WinSetTitle ('Notepad','','Perfect Image Converter 2009')
            EndIf
        Case $ok
            Local $a,$b,$c,$d
            $Split2 = StringSplit (GUICtrlRead($path1),';')
            For $i = 1 to $Split2[0]
                    _GUICtrlListView_AddItem ($list,$Split2[$i])
            next
            $count = _GUICtrlListView_GetItemCount ($list)
            For $i = 0 to $count
                dim $selet = _GUICtrlListView_GetItem ($list,$i)
                Dim $hImage = _GDIPlus_ImageLoadFromFile ($selet[3])
                Dim $iex = _PathSplit ($selet[3],$a,$b,$c,$d)
                ConsoleWrite ($hImage)
                $get = _GUICtrlListView_GetItem ($list,$i)
                _GUICtrlListView_AddSubItem ($list,$i,Round(FileGetSize ($get[3])/1024,1) & ' kB',3)
                _guictrllistview_addsubitem ($list,$i,_GDIPlus_ImageGetWidth ($hImage) & 'x' & _GDIPlus_ImageGetHeight ($hImage),2)
                _guictrllistview_addsubitem ($list,$I,StringTrimLeft (StringUpper($iex[4]),1),1)
            Next
            _cancel ()
        case $convert
            _convert ()
                
        Case $remove
            _remove ()
        case $list
            $select = _GUICtrlListView_GetSelectedIndices ($list,True)
            if not @error Then
                $info = _GUICtrlListView_GetItem ($list,UBound($select,1),4)
                _GUICtrlComboBoxEx_SetCurSel ($combo1,_GUICtrlComboBox_SelectString($combo1,$info[3]))
                $selecteded = _GUICtrlListView_GetSelectedIndices ($list,True)
                if not @error Then
                    _GUICtrlComboBox_SelectString ($combo1,_GUICtrlListView_GetItem ($list,$selecteded[1],4))
                EndIf
            EndIf
            
        Case $combo1
            If _GUICtrlListView_GetItemCount ($list) <> 0 Then
                $selected = _GUICtrlListView_GetSelectedIndices ($list,True)
                if not @error Then
                    _GUICtrlListView_AddSubItem ($list,$selected[1],GUICtrlRead ($combo1),4)
                EndIf
            EndIf
        case $saveb
            $gh = FileSelectFolder ('Browse for destination directory',@DesktopDir,1+4,GUICtrlRead ($savepath),$Form)
            if not @error Then
                GUICtrlSetData ($savepath,$gh)
            EndIf
        case $preview
    ;under construction
EndSwitch   
WEnd
Func _cancel ()
    GUISetState (@SW_HIDE,$addform)
    GUICtrlSetData ($path1,'')
    GUICtrlSetData ($path2,'')
EndFunc
Func _remove ()
    GUICtrlSetState($list, $GUI_FOCUS)
    _GUICtrlListView_GetSelectedIndices ($list,true)
    $re = _GUICtrlListView_DeleteItemsSelected ($list)
    MsgBox (64,'',$re)
EndFunc
Func _convert ()
    _GDIPlus_Startup ()
    Local $e,$f,$g,$h
    Local $saveto = GUICtrlRead ($savepath)
    If $saveto <> '' and _GUICtrlListView_GetItemCount ($List) > 0 Then 
    $count2 = _GUICtrlListView_GetItemCount ($list)
    For $ii = 0 to $count2
        WinSetTitle ($title,'',$title & ' Converting ...')
        $ex = _GUICtrlListView_GetItem ($list,$ii,4)
        $name = _GUICtrlListView_GetItem ($list,$ii)
        $split3 = _PathSplit ($name[3],$e,$f,$g,$h)
        $image = _GDIPlus_ImageLoadFromFile ($name[3])
        $CLSID = _GDIPlus_EncodersGetCLSID ($ex)
        _GDIPlus_ImageSaveToFileEx ($image,$saveto & '\' & $split3[3] & '.' & $ex[3],$CLSID)
        ConsoleWrite ($ex & @CRLF & $name[3] & '.' & $ex)
        If @error Then
            $msg1 = MsgBox (4+16,'Error!','Error occured !' & @CRLF & $name[3] & @CRLF & @CRLF & 'Cancel ? (will continue in 10s)',10,$Form)
            If $msg1 = 2 then 
                WinSetTitle ($title & ' Converting ...','',$title)
                ContinueLoop
            Else
                _GDIPlus_Shutdown ()
            EndIf
            
        EndIf
    Next
    WinSetTitle ($title & ' Converting ...','',$title)
    _GDIPlus_Shutdown ()
    MsgBox (64,'Information','Conversation completed!','',$Form)
Else
    MsgBox (16,'Error!','Please select the destination directory or add an image to convert list!','',$Form)
EndIf

EndFunc

Help : I can't remove item list with _guictrllistview_deleteitemsselected

: How i set value for $combo1 while $list get focus?

: When i clicking to the listbox head bar with no item selected, i got an error :

C:\Documents and Settings\Welcome\Desktop\Image Tools\perfect image converter 1.0.au3 (124) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
_GUICtrlComboBox_SelectString ($combo1,_GUICtrlListView_GetItem ($list,$selecteded[1],4))
_GUICtrlComboBox_SelectString ($combo1,_GUICtrlListView_GetItem ($list,^ ERROR
Edited by logmein
Link to comment
Share on other sites

@logmein

you should ask this question to the general help and support...

I can remove item list with _guictrllistview_deleteitemsselected

:P ??

_GUICtrlListView_DeleteItemsSelected($list)oÝ÷ Ùú+¶¥jËj¹ë-ò¢çÚ"¶X¤zØb±«­¢+Ø%%ÍÉÉä ÀÌØíͱѤQ¡¸(}U%
Ñɱ
½µ½  ½á}M±ÑMÑÉ¥¹ ÀÌØí½µ¼Ä°}U%
Ñɱ1¥ÍÑY¥Ý}Ñ%Ñ´ ÀÌØí±¥ÍаÀÌØíͱÑlÅt°Ð¤¤(¹%oÝ÷ Ù«­¢+Ø%U½Õ¹ ÀÌØíͱѤÐìÀQ¡¸(}U%
Ñɱ
½µ½  ½á}M±ÑMÑÉ¥¹ ÀÌØí½µ¼Ä°}U%
Ñɱ1¥ÍÑY¥Ý}Ñ%Ñ´ ÀÌØí±¥ÍаÀÌØíͱÑlÅt°Ð¤¤(¹%

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Thanks, I replaced 'can' by 'can't'. It completed 95% (5%<95%) so I post it here! :-)

Edited by logmein
Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <WIndowsCOnstants.au3>
#include <GUIListView.au3>
#include <ButtonConstants.au3>
#include <GuiComboBox.au3>
#include <GuiConstantsEx.au3>
#include <GuiComboBoxEx.au3>
#include <GDIPlus.au3>
#include <File.au3>
_GDIPlus_Startup()
Opt('WinTitleMatchMode', 2)
HotKeySet('^r', '_remove')
Dim $title = 'Image Converter'
Dim $x = 'All supported formats (*.JPG;*.JPEG;*.JIB;*.JPC;*.JP2;*.JFIF;*.JIF;*.JPE;*.JNG;*.BMP;*.DIB;*.TIF;*.TIFF;*.PNG;*.GIFF;*.GIF;*.PCX;*.PCD;*.PCC;*.TGA;*.ICO)'

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Welcome\Desktop\Image Tools\imageconverter.kxf
$Form = GUICreate($title, 493, 421, -1, -1)
$savepath = GUICtrlCreateInput("", 56, 8, 391, 21)
$Label1 = GUICtrlCreateLabel("Save to :", 0, 8, 47, 18)
$saveb = GUICtrlCreateButton("...", 448, 7, 43, 23, 0)
$list = GUICtrlCreateListView("Name|Type|Dimensions|Size|Convert to", 1, 56, 490, 358)
$hList = GUICtrlGetHandle($list)
GUICtrlSendMsg(-1, 0x101E, 0, 350)
GUICtrlSendMsg(-1, 0x101E, 1, 50)
GUICtrlSendMsg(-1, 0x101E, 2, 80)
GUICtrlSendMsg(-1, 0x101E, 3, 60)
GUICtrlSendMsg(-1, 0x101E, 4, 80)
$add = GUICtrlCreateButton("&Add", 0, 31, 75, 25, 0)
$remove = GUICtrlCreateButton("Remove", 76, 31, 75, 25, 0)
$combo1 = GUICtrlCreateCombo("", 154, 32, 154, 25)
$hCombo1 = GUICtrlGetHandle($combo1)
GUICtrlSetData(-1, 'JPG|JPEG|JIB|JPC|JP2|JFIF|JIF|JPE|JNG|BMP|DIB|TIF|TIFF|PNG|GIFF|GIF|PCX|PCD|PCC|TGA|ICO')
$convert = GUICtrlCreateButton("&Convert", 310, 31, 92, 25)
GUICtrlSetCursor(-1, 0)
$preview = GUICtrlCreateButton('&Preview', 403, 31, 90, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Welcome\Desktop\Image Tools\add.kxf
$addform = GUICreate("Add Image", 400, 210, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS), BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE), $Form)
$Group1 = GUICtrlCreateGroup("", 0, 0, 390, 180)
$radio1 = GUICtrlCreateLabel("&Add from computer", 9, 16, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Label1 = GUICtrlCreateLabel("Image path (mutiple images seperate by ';')", 9, 40, 208, 18)
$path1 = GUICtrlCreateInput("", 9, 64, 321, 22)
$bpath1 = GUICtrlCreateButton("...", 330, 63, 27, 25, 0)
$expand1 = GUICtrlCreateButton("<>", 357, 63, 27, 25, 0)
$Radio2 = GUICtrlCreateLabel("A&dd from Internet", 9, 96, 113, 17)
$Label2 = GUICtrlCreateLabel("Image URL (mutiple images seperate by ';')", 9, 120, 207, 18)
$path2 = GUICtrlCreateInput("", 9, 144, 345, 22)
$expand2 = GUICtrlCreateButton("<>", 355, 143, 27, 25, 0)
;$Label3 = GUICtrlCreateLabel("Convert to :", 9, 176, 60, 18)
;$combo2 = GUICtrlCreateCombo("Combo1", 73, 176, 145, 25)
;GUICtrlSetData(-1, "JPG|JPEG|JFIF")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ok = GUICtrlCreateButton("&Add", 8, 183, 75, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$cancel = GUICtrlCreateButton("&Cancel", 88, 183, 75, 25, 0)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $add
            GUISetState(@SW_SHOW, $addform)
        Case $cancel
            _cancel()
        Case $bpath1
            $bpathgui = FileOpenDialog('Browse for image', @DesktopDir, $x, 1 + 4, '', $addform)
            If Not @error Then
                $Split1 = StringSplit($bpathgui, '|')
                If Not @error Then
                    For $i = 2 To $Split1[0]
                        GUICtrlSetData($path1, GUICtrlRead($path1) & ';' & $Split1[1] & '\' & $Split1[$i])
                    Next
                Else
                    GUICtrlSetData($path1, GUICtrlRead($path1) & ';' & $bpathgui)
                EndIf

                If StringLeft(GUICtrlRead($path1), 1) = ';' Then
                    GUICtrlSetData($path1, StringTrimLeft(GUICtrlRead($path1), 1))
                EndIf
                If StringRight(GUICtrlRead($path1), 1) = ';' Then
                    GUICtrlSetData($path1, StringTrimRight(GUICtrlRead($path1), 1))
                EndIf
            EndIf
        Case $expand1
            ShellExecute('notepad.exe')
            If WinWaitActive('Notepad') Then

                ControlSetText('Notepad', '', 'Edit1', StringReplace(GUICtrlRead($path1), ';', @CRLF))
                WinSetTitle('Notepad', '', 'Perfect Image Converter 2009')
            EndIf
        Case $ok
            Local $a, $b, $c, $d
            $Split2 = StringSplit(GUICtrlRead($path1), ';')
            For $i = 1 To $Split2[0]
                _GUICtrlListView_AddItem($list, $Split2[$i])
            Next
            $count = _GUICtrlListView_GetItemCount($hList)
            For $i = 0 To $count
                Dim $selet = _GUICtrlListView_GetItem($hList, $i)
                Dim $hImage = _GDIPlus_ImageLoadFromFile($selet[3])
                Dim $iex = _PathSplit($selet[3], $a, $b, $c, $d)
                ConsoleWrite($hImage)
                $get = _GUICtrlListView_GetItem($hList, $i)
                _GUICtrlListView_AddSubItem($hList, $i, Round(FileGetSize($get[3]) / 1024, 1) & ' kB', 3)
                _GUICtrlListView_AddSubItem($hList, $i, _GDIPlus_ImageGetWidth($hImage) & 'x' & _GDIPlus_ImageGetHeight($hImage), 2)
                _GUICtrlListView_AddSubItem($hList, $i, StringTrimLeft(StringUpper($iex[4]), 1), 1)
            Next
            _cancel()
        Case $convert
            _convert()

        Case $remove
            _remove()
        Case $list
            $select = _GUICtrlListView_GetSelectedIndices($hList, True)
            If Not @error Then
                $info = _GUICtrlListView_GetItem($hList, UBound($select, 1), 4)
                _GUICtrlComboBoxEx_SetCurSel($hCombo1, _GUICtrlComboBox_SelectString($hCombo1, $info[3]))
                $selecteded = _GUICtrlListView_GetSelectedIndices($hList, True)
                If Not @error Then
                    _GUICtrlComboBox_SelectString($hCombo1, _GUICtrlListView_GetItem($hList, $selecteded[1], 4))
                EndIf
            EndIf

        Case $combo1
            If _GUICtrlListView_GetItemCount($hList) <> 0 Then
                $selected = _GUICtrlListView_GetSelectedIndices($hList, True)
                If Not @error And $selected[0] Then
                    _GUICtrlListView_AddSubItem($hList, $selected[1], GUICtrlRead($combo1), 4)
                EndIf
            EndIf
        Case $saveb
            $gh = FileSelectFolder('Browse for destination directory', @DesktopDir, 1 + 4, GUICtrlRead($savepath), $Form)
            If Not @error Then
                GUICtrlSetData($savepath, $gh)
            EndIf
        Case $preview
            ;under construction
    EndSwitch
WEnd
Func _cancel()
    GUISetState(@SW_HIDE, $addform)
    GUICtrlSetData($path1, '')
    GUICtrlSetData($path2, '')
EndFunc   ;==>_cancel
Func _remove()
    GUICtrlSetState($list, $GUI_FOCUS)
    _GUICtrlListView_GetSelectedIndices($hList, True)
    $re = _GUICtrlListView_DeleteItemsSelected($hList)
    MsgBox(64, '', $re)
EndFunc   ;==>_remove
Func _convert()
    _GDIPlus_Startup()
    Local $e, $f, $g, $h
    Local $saveto = GUICtrlRead($savepath)
    If $saveto <> '' And _GUICtrlListView_GetItemCount($hList) > 0 Then
        $count2 = _GUICtrlListView_GetItemCount($hList)
        For $ii = 0 To $count2
            WinSetTitle($title, '', $title & ' Converting ...')
            $ex = _GUICtrlListView_GetItem($hList, $ii, 4)
            $name = _GUICtrlListView_GetItem($hList, $ii)
            $split3 = _PathSplit($name[3], $e, $f, $g, $h)
            $image = _GDIPlus_ImageLoadFromFile($name[3])
            $CLSID = _GDIPlus_EncodersGetCLSID($ex)
            _GDIPlus_ImageSaveToFileEx($image, $saveto & '\' & $split3[3] & '.' & $ex[3], $CLSID)
            ConsoleWrite($ex & @CRLF & $name[3] & '.' & $ex)
            If @error Then
                $msg1 = MsgBox(4 + 16, 'Error!', 'Error occured !' & @CRLF & $name[3] & @CRLF & @CRLF & 'Cancel ? (will continue in 10s)', 10, $Form)
                If $msg1 = 2 Then
                    WinSetTitle($title & ' Converting ...', '', $title)
                    ContinueLoop
                Else
                    _GDIPlus_Shutdown()
                EndIf

            EndIf
        Next
        WinSetTitle($title & ' Converting ...', '', $title)
        _GDIPlus_Shutdown()
        MsgBox(64, 'Information', 'Conversation completed!', '', $Form)
    Else
        MsgBox(16, 'Error!', 'Please select the destination directory or add an image to convert list!', '', $Form)
    EndIf

EndFunc   ;==>_convert

I don't think that handles and ID mixing is that bad idea but I'd keep myself out of doing it... Also fixed your $selected var because you didn't check the $selected[0] is greater than 0 before calling _GUICtrlListView_AddSubItem() which may result in run-time error.

Hope it's working for you.

Edit: Nice share btw, works great, thank you ;].

Edited by Authenticity
Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...