Jump to content

Gifs in Autoit?


elgabionline
 Share

Recommended Posts

Hi! I Just trying... My first attempt here:

#include <guiconstants.au3>

GUICreate ("Show Gif",200,150)
_guictrlcreategif ("http://www.autoitscript.com/forum/style_emoticons/autoit/idea.gif",10,10,22,26)
GUISetState ()
While 1
    $msg=GUIGetMsg ()
    if $msg=$GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete ()
filedelete (@tempdir&"\gifload")
Exit

Func _GUICtrlCreateGif ($s_path,$n_left,$n_top,$n_width,$n_height,$o_Gif=-1)

        If $o_Gif=-1 Then $o_Gif=ObjCreate ("Shell.Explorer.2")

        If IsObj ($o_Gif) Then
            Local $h_control=GUICtrlCreateObj ($o_Gif,$n_left,$n_top,$n_width+4,$n_height+4)
            $h_file=FileOpen (@TempDir&"\gifload",2)
            $s_line='<BODY background="'&$s_path&'" Scroll="No">'
            FileWriteLine ($h_file,"<HTML>")
            FileWriteLine ($h_file,$s_line)
            FileWriteLine ($h_file,"</BODY>")
            FileWriteLine ($h_file,"</HTML>")
            FileClose ($h_file)
            $o_Gif.navigate (@TempDir&"\gifload")
            Return $h_control
        Else
            SetError (1)
            Return False
        EndIf
EndFunc

I made this, but it stinks...

is there some better way to show animated gifs?

I listen for suggestions!! :">

Link to comment
Share on other sites

$oIE = ObjCreate("Shell.Explorer.2")
GUICreate("Embedded Web control Test", 640, 580)
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 250, 100)
$oIE.navigate (@ScriptDir & '\Happy_Birthday_Gross.gif')
$oIE.document.body.scroll = "no"
GUISetState()
While GUIGetMsg() <> -3
WEnd

Edit: Added no scroll so you can see that you can make it any size you want in the gui.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Here's something else you might find interesting when working with gifs

_Main()

Func _Main()
    Local $pheight, $pwidth, $oIE, $GUIActiveX, $gif = @ScriptDir & '\Happy_Birthday_Gross.gif'
    _GetGifPixWidth_Height($gif, $pwidth, $pheight)

    $oIE = ObjCreate("Shell.Explorer.2")
    GUICreate("Embedded Web control Test", 640, 580)
    $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $pwidth + 16, $pheight + 21)
    $oIE.navigate ($gif)
    $oIE.document.body.scroll = "no"
    GUISetState()
    While GUIGetMsg() <> -3
    WEnd
EndFunc   ;==>_Main

Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight)
    If FileGetSize($s_gif) > 9 Then
        Local $sizes = FileRead($s_gif, 10)
        ConsoleWrite("Gif version: " & StringMid($sizes,1,6) & @LF)
        $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1))
        $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1))
        ConsoleWrite($pwidth & " x " & $pheight & @LF)
    EndIf
EndFunc   ;==>_GetGifPixWidth_Height

it appears the width is off by 9 pixels on this gif from the formula i found on the web

i've tried it with a few others and it seems to be right on the money.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Here's something else you might find interesting when working with gifs

Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight)
    If FileGetSize($s_gif) > 9 Then
        Local $sizes = FileRead($s_gif, 10)
        ConsoleWrite("Gif version: " & StringMid($sizes,1,6) & @LF)
        $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1))
        $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1))
        ConsoleWrite($pwidth & " x " & $pheight & @LF)
    EndIf
EndFunc   ;==>_GetGifPixWidth_Height

it appears the width is off by 9 pixels on this gif from the formula i found on the web

i've tried it with a few others and it seems to be right on the money.

Yes yes yes... that code works!! and really nice!

@gafrost: A lot of thanks for help me with my... "scrap" :)

Link to comment
Share on other sites

Yes yes yes... that code works!! and really nice!

@gafrost: A lot of thanks for help me with my... "scrap" :)

yw

looks like the ie embedded has an offset edge so it don't actually start the gif on 0,0 but rather 25 pixels from the left and 35 pixels from the top

to test it i had a square gif with a dark background to try to get the a frame look around the gif

here's what i used:

; add to width and height, ie obj starts the image approx. on those pixel coords
    $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $pwidth + 25, $pheight + 35)
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

looks like the ie embedded has an offset edge so it don't actually start the gif on 0,0 but rather 25 pixels from the left and 35 pixels from the top

Yes.. I can see that. I try with this code, and the edge shouldn't appear. But neither the gif appears!

_Main()

Func _Main()
    Local $pheight, $pwidth, $oIE, $GUIActiveX, $gif = @DesktopDir&"\Happy_Birthday_Gross.gif"; I put the image there... :)
    _GetGifPixWidth_Height($gif, $pwidth, $pheight)

    $oIE = ObjCreate("Shell.Explorer.2")
    GUICreate("Embedded Web control Test", 640, 580)
    $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $pwidth, $pheight)
    With $oIE
        .navigate ("about:blank")
        .document.body.background=$gif
        .document.body.scroll = "no"
    EndWith
    GUISetState()
    While GUIGetMsg() <> -3
    WEnd
EndFunc   ;==>_Main

Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight)
    If FileGetSize($s_gif) > 9 Then
        Local $sizes = FileRead($s_gif, 10)
        ConsoleWrite("Gif version: " & StringMid($sizes,1,6) & @LF)
        $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1))
        $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1))
        ConsoleWrite($pwidth & " x " & $pheight & @LF)
    EndIf
EndFunc   ;==>_GetGifPixWidth_Height

Depending on the order I puts them in Width-EndWith, scroll bar not appears or the image appears. Not both... :)

Edited by elgabionline
Link to comment
Share on other sites

Func _Main()
    Local $pheight, $pwidth, $oIE, $GUIActiveX, $gif = @ScriptDir & '\biplane_landing.gif'
    _GetGifPixWidth_Height($gif, $pwidth, $pheight)

    $oIE = ObjCreate("Shell.Explorer.2")
    GUICreate("Embedded Web control Test", 640, 580)
    $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $pwidth, $pheight)
    $oIE.navigate ("about:blank")
    $oIE.document.body.background = $gif
    $oIE.document.body.scroll = "no"
    GUISetState()
    While GUIGetMsg() <> -3
    WEnd
EndFunc ;==>_Main

Edited by Jon

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I suspect in using With it doens't apply the settings untill the EndWith and IE may not apply those settings in the order you want them to.

Thanks both elgabionline & gafrost... good piece of code!!!

Is there any way to stop/resume animation? :)

Link to comment
Share on other sites

Almost that easy.

Opt("MustDeclareVars", 1)
#include <GuiConstants.au3>
#include <IE.au3>

_Main()

Func _Main()
    Local $GUI, $pheight = 50, $pwidth = 50, $oIE, $GUIActiveX, $gif, $btn_toggle, $msg
    Local $animated = 1, $btn_text[2] = ["Start", "Stop"]
    $gif = FileOpenDialog("Select Animated Gif", @ScriptDir, "gif files (*.gif)", 3)
    If @error Then Exit
    _GetGifPixWidth_Height($gif, $pwidth, $pheight)
    $oIE = ObjCreate("Shell.Explorer.2")
    $GUI = GUICreate("Embedded Web control Test", 640, 580)
    $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $pwidth, $pheight)
    _StartGif($GUI, $oIE, $gif)
    $btn_toggle = GUICtrlCreateButton($btn_text[$animated], ($pwidth / 2) - 45, $pheight + 10, 90, 20)
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btn_toggle
                $animated = Not $animated
                GUICtrlSetData($btn_toggle, $btn_text[$animated])
                If $animated Then
                    _StartGif($GUI, $oIE, $gif)
                Else
                    _IEAction($oIE, "stop") ; stop
                EndIf
        EndSwitch
        
    WEnd
EndFunc   ;==>_Main

Func _StartGif($GUI, $oIE, $gif, $noborder = 0)
    GUISetState(@SW_LOCK, $GUI)
    $oIE.navigate ("about:blank")
    While _IEPropertyGet($oIE, "busy")
        Sleep(100)
    WEnd
    $oIE.document.body.background = $gif
    $oIE.document.body.scroll = "no"
    If $noborder Then $oIE.document.body.style.border = "0px"
    GUISetState(@SW_UNLOCK, $GUI)
EndFunc   ;==>_StartGif

Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight)
    If FileGetSize($s_gif) > 9 Then
        Local $sizes = FileRead($s_gif, 10)
        ConsoleWrite("Gif version: " & StringMid($sizes, 1, 6) & @LF)
        $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1))
        $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1))
        ConsoleWrite($pwidth & " x " & $pheight & @LF)
    EndIf
EndFunc   ;==>_GetGifPixWidth_Height
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 2 weeks later...

Until someone of you do something better... I propose this UDF...

Functions are:

_GUICtrlCreateGIF() ;create an animated gif

_GUICtrlStopGIF() ;stops an animation

_GUICtrlResumeGIF() ;resume animation

This UDF would't be possible without: elgabionline, gafrost and lod3n

;===============================================================================
;   UDF Name: _AnimatedGif.au3 
;
;   Version v1.0.0  Oct 12, 2006, built with Autoit 3.2.1.3
;
;   Authors:  gafrost, elgabionline, lod3n
;
;   Contribution: Ed_Maximized
;   
;   Email: <edmundofasano [at] gmail [dot] com>
;   
;   Use: Creation of an animated GIF control and functions to stop/resume animation
;===============================================================================
#include-once
;===============================================================================
;
; Function Name:    _GUICtrlCreateGIF()
; Description:      Create an Animated GIF control
; Parameter(s):     $gif        [required]      path and filename of the animated GIF
;                   $x          [optional]      x pos of the top-left corner
;                   $y          [optional]      y pos of the top-left corner
;                   $border     [optional]      0 = no border
;                                               any other = sunken border
; Requirement(s):   #include <IE.au3>
; Return Value(s):  
;                   controlID of the control created
; Author(s):        elgabionline, gafrost, Ed_Maximized
;
;===============================================================================
Func _GUICtrlCreateGIF($gif,$x=0,$y=0,$border=0)
    Local $pwidth,$pheight,$oIE,$GUIActiveX
    _GetGifPixWidth_Height($gif, $pwidth, $pheight)
    $oIE = ObjCreate("Shell.Explorer.2")
    $GUIActiveX = GUICtrlCreateObj($oIE, $x, $y, $pwidth, $pheight)
    $oIE.navigate ("about:blank")
    While _IEPropertyGet($oIE, "busy")
        Sleep(100)
    WEnd
    $oIE.document.body.background = $gif
    $oIE.document.body.scroll = "no"
    if $border=0 then $oIE.document.body.style.border = "0px"
    Return $oIE
EndFunc
;===============================================================================
;
; Function Name:    _GUICtrlStopGIF()
; Description:      stop an Animated GIF control created with _GUICtrlCreateGIF()
; Parameter(s):     $Control    [required]      controlID of the control returned by _GUICtrlCreateGIF()
;                                               
; Requirement(s):   #include <IE.au3>
; Return Value(s):  
;                   none
; Author(s):        lod3n, Ed_Maximized
;
;===============================================================================
Func _GUICtrlStopGIF($Control)
    _IEAction ($Control, "stop" ) ; stop
EndFunc
;===============================================================================
;
; Function Name:    _GUICtrlResumeGIF()
; Description:      resume an Animated GIF control created with _GUICtrlCreateGIF()
; Parameter(s):     $Control    [required]      controlID of the control returned by _GUICtrlCreateGIF()
;                                               
; Requirement(s):   #include <IE.au3>
; Return Value(s):  
;                   none
; Author(s):        lod3n, Ed_Maximized
;
;===============================================================================
Func _GUICtrlResumeGIF($Control)
    $Control.document.body.background = $Control.document.body.background ;resume
EndFunc
;===============================================================================
;
; Function Name:    _GetGifPixWidth_Height()
; Description:      return the size of a GIF image in pixels
; Parameter(s):     $s_gif      [required]      path and filename of the animated GIF
;                                               
; Requirement(s):   #include <IE.au3>
; Return Value(s):  
;                   $pwidth = width of the GIF in pixels
;                   $pheight = height of the GIF in pixels
; Author(s):        gafrost
;
;===============================================================================
Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight)
    If FileGetSize($s_gif) > 9 Then
        Local $sizes = FileRead($s_gif, 10)
        ConsoleWrite("Gif version: " & StringMid($sizes, 1, 6) & @LF)
        $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1))
        $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1))
        ConsoleWrite($pwidth & " x " & $pheight & @LF)
    EndIf
EndFunc   ;==>_GetGifPixWidth_Height


oÝ÷ Ù7¬·­Øb±ìZ^jëh×6
; Animated Gif Example
; Author - Ed_Maximized

Opt("MustDeclareVars", 1)
#include <IE.au3>
#include <GUIConstants.au3>
#include <_AnimatedGIF.au3>

_Main()

Func _Main()
    Local $pheight = 50, $pwidth = 50, $gif, $gif_control, $Form1, $Button1, $Button2, $msg
    $gif = FileOpenDialog("Select Animated Gif", @ScriptDir, "gif files (*.gif)", 3)
    If @error Then Exit
    $Form1 = GUICreate("Animated GIF demo", 622, 448, 192, 125)
    $Button1 = GUICtrlCreateButton("Stop", 8, 8, 81, 25)
    $Button2 = GUICtrlCreateButton("Resume", 96, 8, 81, 25)
    $gif_control=_GUICtrlCreateGIF($gif,8,40,0)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GuiGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg=$Button1
            _GUICtrlStopGIF($gif_control)
        Case $msg=$Button2
            _GUICtrlResumeGIF($gif_control)
        Case Else
            ;;;;;;;
        EndSelect
    WEnd
    Exit
EndFunc

Comments and improvements wellcome

Ed :lmao:

Link to comment
Share on other sites

  • 1 year later...

Took me a long time, but managed to change the first bit slightly to display an animated gif in lieu of an icon and put an OK button in.

I haven't yet successfully incorporated this into a script so that it works, but this is slightly different use of the example script given here that I thought might be of help to other newbies, even if to just get an idea from it <g>:

Opt("MustDeclareVars", 1)
#include <IE.au3>
#include <GUIConstants.au3>
#include <_AnimatedGIF.au3>

_BoxWithAnimatedGIF()

Func _BoxWithAnimatedGIF()
    Local $pheight = 50, $pwidth = 50, $gif, $gif_control, $Label1, $Form1, $OK_Button, $msg
    $gif = @ScriptDir & "\Box with animated GIF + OK button.gif"
    If @error Then Exit
    $Form1 = GUICreate("Reminder!", 180, 85, 700, 120, -1, $WS_EX_TOPMOST)     ; width, height, left, top, "-1, $WS_EX_TOPMOST" makes GUI ontop
    $Label1 = GUICtrlCreateLabel("Don't forget ...", 60, 15, 575, 25);  Left, Right, Width, Height of inside text box.
    $OK_Button = GUICtrlCreateButton("OK", 60, 50, 65, 25)     ; left, top, width, height
    $gif_control=_GUICtrlCreateGIF($gif,15,15,0)     ; width, height, left, top
    GUISetState(@SW_SHOW)
    While 1
        $msg = GuiGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg=$OK_Button
            Exit     ; finished
        Case Else
            ;;;;;;;
        EndSelect
    WEnd
    Exit
EndFunc

The animated gif shows up in the style of a flashing exclamation point icon.

:P

Link to comment
Share on other sites

  • 1 month later...

Thanks to "GaryFrost" for wonderful and easy to understand code/example. it's great because i was trying for a long time for it.

Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
Link to comment
Share on other sites

  • 3 years later...

I want to show GIF and then delete the control to display an AVI, which command deletes the control of GIF?

_GUICtrlCreateGIF() ;create an animated gif

_GUICtrlStopGIF() ;stops an animation

_GUICtrlResumeGIF() ;resume animation

_GUICtrldeleteGIF() ;????????????????

link post:

Edited by Belini
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...