Jump to content

Need to add more image suport


Recommended Posts

I got this script from an animated gif example. I need a way to add support for all image types, and a way to resize the images. The end script will be what i open my images with. Anyone know how to add support for .bmp,.jpg,.png, and other formats?

#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <gif.au3>
#include <File.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)

Global $sFile 
If $CmdLine[0] > 0 Then
    $sFile = $CmdLine[1]
Else
    $sFile = FileOpenDialog("Choose gif", "", "(*.gif)")
    If @error Then Exit
EndIf

Global $hGui = GUICreate("Image viewer", 500, 500, -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetBkColor(0xFFFFFF)

Global $aGIFDimension = _GIFGetDimension($sFile)
Global $aClientSize = WinGetClientSize($hGui)
Global $iPosX = ($aClientSize[0] - $aGIFDimension[0]) / 2
Global $iPosY = ($aClientSize[1] - $aGIFDimension[1]) / 2 - 100
If $iPosY < 0 Then $iPosY = 0
If $iPosY + $aGIFDimension[1] > 400 Then $iPosY -= $aGIFDimension[1] - 400; not to cover buttons

Global $sDrive, $sDir, $sFName, $sExt

Global $aGIFFilesArray = _FileListToArray(@WorkingDir, "*.gif", 1)
Global $aSplitPath = _PathSplit($sFile, $sDrive, $sDir, $sFName, $sExt)
Global $current_position = _ArraySearch($aGIFFilesArray, $aSplitPath[3] & $aSplitPath[4])

Global $aGIFArrayOfIconHandles
Global $hGIFThread
Global $iGIFTransparent
Global $tFrameCurrent

Global $hGIF = _GUICtrlCreateGIF($sFile, $iPosX, $iPosY, $aGIFArrayOfIconHandles, $hGIFThread, $iGIFTransparent, $tFrameCurrent)
GUICtrlSetResizing(-1, 770)

Global $hButton = GUICtrlCreateButton("<  Previous", 50, 450, 100, 25)
GUICtrlSetResizing(-1, 836)
Global $hButton1 = GUICtrlCreateButton("Stop animation", 200, 450, 100, 25)
GUICtrlSetResizing(-1, 836)
Global $hButton2 = GUICtrlCreateButton("Next  >", 350, 450, 100, 25)
GUICtrlSetResizing(-1, 836)

If UBound($aGIFArrayOfIconHandles) = 1 Then
    GUICtrlSetData($hButton1, "Not animated")
    GUICtrlSetState($hButton1, $GUI_DISABLE)
EndIf

GUIRegisterMsg(15, "_Refresh"); WM_PAINT
GUIRegisterMsg(5, "_AdjustGIFPos"); WM_SIZE
GUIRegisterMsg(36, "_SetMinMax"); WM_GETMINMAXINFO

Global $iPlay = 1

GUISetState()


While 1

    Switch GUIGetMsg()
        Case - 3
            Exit
        Case $hButton
            GUISetCursor(15, 1)
            GUICtrlSetData($hButton1, "Stop animation")
            GUICtrlSetState($hButton, $GUI_DISABLE)
            GUICtrlSetState($hButton1, $GUI_DISABLE)
            GUICtrlSetState($hButton2, $GUI_DISABLE)
            _Back()
            GUICtrlSetState($hButton, $GUI_ENABLE)
            GUICtrlSetState($hButton1, $GUI_ENABLE)
            GUICtrlSetState($hButton2, $GUI_ENABLE)
            GUISetCursor(-1)
            $iPlay = 1
            If UBound($aGIFArrayOfIconHandles) = 1 Then
                GUICtrlSetData($hButton1, "Not animated")
                GUICtrlSetState($hButton1, $GUI_DISABLE)
            Else
                GUICtrlSetState($hButton1, $GUI_ENABLE)
            EndIf
        Case $hButton1
            If $iPlay Then
                If _StopGIFAnimation($hGIFThread) Then
                    $iPlay = 0
                    GUICtrlSetData($hButton1, "Resume animation")
                EndIf
            Else
                If _ResumeGIFAnimation($hGIFThread) Then
                    $iPlay = 1
                    GUICtrlSetData($hButton1, "Stop animation")
                EndIf
            EndIf
        Case $hButton2
            GUISetCursor(15, 1)
            GUICtrlSetData($hButton1, "Stop animation")
            GUICtrlSetState($hButton, $GUI_DISABLE)
            GUICtrlSetState($hButton1, $GUI_DISABLE)
            GUICtrlSetState($hButton2, $GUI_DISABLE)
            _Forward()
            GUICtrlSetState($hButton, $GUI_ENABLE)
            GUICtrlSetState($hButton1, $GUI_ENABLE)
            GUICtrlSetState($hButton2, $GUI_ENABLE)
            GUISetCursor(-1)
            $iPlay = 1
            If UBound($aGIFArrayOfIconHandles) = 1 Then
                GUICtrlSetData($hButton1, "Not animated")
                GUICtrlSetState($hButton1, $GUI_DISABLE)
            Else
                GUICtrlSetState($hButton1, $GUI_ENABLE)
            EndIf
    EndSwitch

WEnd





Func _Back()

    _GUICtrlDeleteGIF($hGIF, $aGIFArrayOfIconHandles, $hGIFThread, $tFrameCurrent)

    If $current_position > 1 Then
        $current_position -= 1
    Else
        $current_position = $aGIFFilesArray[0]
    EndIf

    $aGIFDimension = _GIFGetDimension($aGIFFilesArray[$current_position])
    $aClientSize = WinGetClientSize($hGui)
    $iPosX = ($aClientSize[0] - $aGIFDimension[0]) / 2
    $iPosY = ($aClientSize[1] - $aGIFDimension[1]) / 2 - 100
    If $iPosY < 0 Then $iPosY = 0
    If $iPosY + $aGIFDimension[1] > $aClientSize[1] - 100 Then $iPosY -= $aGIFDimension[1] - $aClientSize[1] + 100; not to cover buttons
    $hGIF = _GUICtrlCreateGIF($aGIFFilesArray[$current_position], $iPosX, $iPosY, $aGIFArrayOfIconHandles, $hGIFThread, $iGIFTransparent, $tFrameCurrent)

EndFunc ;==>_Back


Func _Forward()

    _GUICtrlDeleteGIF($hGIF, $aGIFArrayOfIconHandles, $hGIFThread, $tFrameCurrent)

    If $current_position < $aGIFFilesArray[0] Then
        $current_position += 1
    Else
        $current_position = 1
    EndIf

    $aGIFDimension = _GIFGetDimension($aGIFFilesArray[$current_position])
    $aClientSize = WinGetClientSize($hGui)
    $iPosX = ($aClientSize[0] - $aGIFDimension[0]) / 2
    $iPosY = ($aClientSize[1] - $aGIFDimension[1]) / 2 - 100
    If $iPosY < 0 Then $iPosY = 0
    If $iPosY + $aGIFDimension[1] > $aClientSize[1] - 100 Then $iPosY -= $aGIFDimension[1] - $aClientSize[1] + 100; not to cover buttons
    $hGIF = _GUICtrlCreateGIF($aGIFFilesArray[$current_position], $iPosX, $iPosY, $aGIFArrayOfIconHandles, $hGIFThread, $iGIFTransparent, $tFrameCurrent)

EndFunc ;==>_Forward


Func _Refresh($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam, $lParam

    _RefreshGIF($hGIF, $aGIFArrayOfIconHandles, $hGIFThread, $iGIFTransparent, $tFrameCurrent)

EndFunc ;==>_Refresh


Func _AdjustGIFPos($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $aClientSize[2] = [BitAND($lParam, 65535), BitShift($lParam, 16)]

    $iPosX = ($aClientSize[0] - $aGIFDimension[0]) / 2
    $iPosY = ($aClientSize[1] - $aGIFDimension[1]) / 2 - 100
    If $iPosY < 0 Then $iPosY = 0
    If $iPosY + $aGIFDimension[1] > $aClientSize[1] - 100 Then $iPosY -= $aGIFDimension[1] - $aClientSize[1] + 100; not to cover buttons

    GUICtrlSetPos($hGIF, $iPosX, $iPosY, $aGIFDimension[0], $aGIFDimension[1])

EndFunc ;==>_AdjustGIFPos


Func _SetMinMax($hWnd, $iMsg, $wParam, $lParam)

    #forceref $iMsg, $wParam
    If $hWnd = $hGui Then
        Local $tMINMAXINFO = DllStructCreate("int[2];" & _
                "int MaxSize[2];" & _
                "int MaxPosition[2];" & _
                "int MinTrackSize[2];" & _
                "int MaxTrackSize[2]", _
                $lParam)

        DllStructSetData($tMINMAXINFO, "MinTrackSize", 500, 1)
        DllStructSetData($tMINMAXINFO, "MinTrackSize", 350, 2)
    EndIf

EndFunc ;==>_SetMinMax

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

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