Jump to content

GIF Animation (cached)


Nine
 Share

Recommended Posts

Found another problem when all GIFs were deleted and new ones start being recreated.  I needed to remove some logic out of the adlib function and store that logic in the delete function.

And repeating AdLibRegister is also solved.

Link to comment
Share on other sites

Bravo Nine, it works fine now :thumbsup:
Good catch for disposing image(s) & graphic(s), not only when user quits the script, but also during the control deletion phase. When the script displays 1 gif only (index 0), ConsoleWrite(s) correctly show this :

1 gif : Quit after this gif has been deleted, then recreated
============================================================
Creating 0
AdlibRegister
Deleting 0
Disposing 0
Adlib UnRegister
Recreating 0
AdlibRegister
QUIT : FINAL UnRegister
QUIT : Disposing 0

 

Edited by pixelsearch
typo
Link to comment
Share on other sites

Link to comment
Share on other sites

  • 1 month later...

Very good UDF, it works very well.:thumbsup:,

Thank Nine for your hard work!

If  can realize the image Zoom function further,

as the web page shows the picture to Zoom (in or out) automatically according to the given Area(width and height).

Or cut automatically so that the center of Gif is always at the center of a given area

if so ,it will be more perfect

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "Cached GIF Animation.au3"

Example()

Func Example()
    GUICreate("GUI", 350, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU)

    GUISetBkColor(0xE0FFFF)
    Local $IMG_Ctrl = _GUICtrlCreateAnimGIF("9.gif", 10, 10, 330, 172, -1, $GUI_WS_EX_PARENTDRAG)
    Local $idButton_Close = GUICtrlCreateButton("close", 255, 190, 85, 25)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE,$idButton_Close
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example

 

9.gif

Edited by Letraindusoir
Link to comment
Share on other sites

@Letraindusoir Thanks. Glad you like it.

I believe it could be possible to modify each frames by zoom, crop, resize or distord.   BUT, I also think it may jeopardize the performance of the UDF, and erase the speed benefit gains with cached approach.  By, transforming frame after frame repeatedly at high speed, I am afraid that the whole performance of UDF may suffer.

So I suggest you use one of the free tools available over the web to modify your GIF exactly as you wish to have it prior to use the UDF.  I have done it in the past successfully.

Link to comment
Share on other sites

9 hours ago, Nine said:

...one of the free tools available over the web to modify your GIF

Eddie Kohler wrote a command-line utility named Gsicle, it's worth a try for resizing, cropping, merging animated gifs. But it sure needs you to read its documentation first, at least concerning the function(s) you wanna use.

I used it in the past to merge some gifs and re-used it just now to crop or resize the gif uploaded by letraindusoir

Link to comment
Share on other sites

Using third-party software to reduce Gif achieve the purpose of scaling Gif, although feasible, but still lack of convenience.
How about a different way, for example, to mask or shade the parts of the GIF beyond a given area?


As shown below, the lower right part of the Gif is masked or hidden because it is beyond a given area of the GUI.
If the upper left part of the Gif can also be treated like this,if or not achieve the goal?
Using the negative coordinates and subwindow can probably achieve this goal, but it feels a little inconvenient....20210220205013.png.b72d4938d8d9177273952d52d1b6cada.png

Edited by Letraindusoir
Link to comment
Share on other sites

Nice idea Letraindusoir. Cropping shouldn't be a problem using negative values, what follows works for me (using the original pic renamed letrain.gif)
You just got to determine how much you want to crop :

; Local $IMG_Ctrl = _GUICtrlCreateAnimGIF("letrain.gif", 10, 10, 330, 172, -1, $GUI_WS_EX_PARENTDRAG)

Local $IMG_Ctrl = _GUICtrlCreateAnimGIF("letrain.gif", -30, -90, 380, 192, -1, $GUI_WS_EX_PARENTDRAG)

letraindusoir1.png.6bc66ead7bd5f1bba31dd22df7506a66.png

Edited by pixelsearch
Added pic result
Link to comment
Share on other sites

The "problem" with my precedent pic is that it will always be placed at 0,0 in the GUI, which is maybe not what the user wants.

If you want the pic to be placed at your exact coords (10,10 to 330,172) then you can create a child window having these exact coords, it's easy to script and the result looks fine :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "Cached GIF Animation.au3"

Example()

Func Example()
    $hGUI = GUICreate("GUI", 350, 250, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_EX_COMPOSITED)
    GUISetBkColor(0xE0FFFF)

    $hGUI2 = GUICreate("", 330, 172, 10, 10, $WS_CHILD, -1, $hGUI)
    Local $IMG_Ctrl = _GUICtrlCreateAnimGIF("letrain.gif", -35, -90, 330 + 35, 172 + 90)

    GUISwitch($hGUI)

    Local $idButton_Close = GUICtrlCreateButton("close", 255, 190, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)
    GUISetState(@SW_SHOW, $hGUI2)


    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE,$idButton_Close
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example

letraindusoir2.png.be437b63ad0f0fbd159a6841e65ea809.png

Nine's way (cropping it online) is sure the quickest way to do it, but it's interesting to know that we can find a solution in pure AutoIt language... while using the original animated gif :)

Edited by pixelsearch
typo
Link to comment
Share on other sites

  • 11 months later...

Hi!

I get this error when I try to run the example sketch included in the udf's zip:

Quote

warning: $GDIP_FRAMEDIMENSION_TIME: possibly used before declaration.
  $iNumberOfFrames = _GDIPlus_ImageGetFrameCount($hImage, $GDIP_FRAMEDIMENSION_TIME)

 

Link to comment
Share on other sites

  • 7 months later...

Hello Nine,Glad to see that you added double buffering to this UDF,I tried many UDFs  to creat a png button,all of them cause flickering except your UDF.

But,there's something I still don‘t understand. What's wrong with this countdown gif, It  is  overlapping.

Global $IMG_Ctrl1 = _GUICtrlCreateAnimGIF("1.gif", 150, 50, 285, 280, -1, $GUI_WS_EX_PARENTDRAG, False, 0 )

I tried to change the $nBackColor to  0,it works.But if there is a backgroud picture ,It is overlapping again.

97964449_-1.jpg.8061c0416ad9953e2f4b02b6367f110d.jpg

Animated GIF Multiple.rar

 

Edited by ling3882688
Link to comment
Share on other sites

@ling3882688  I have found a decent way to achieve it.

Here the example using your background image and your GIF.

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include "Cached GIF Animation.au3"

OnAutoItExitRegister(_GIF_Animation_Quit)

Local $hGUI = GUICreate("GIF Animation", 800, 600, -1, -1, $WS_POPUP, $WS_EX_CONTROLPARENT)
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $hOrig = _GDIPlus_ImageLoadFromFile("bg.png")
Local $hImage = _GDIPlus_ImageResize($hOrig, 800, 600)
_GDIPlus_ImageDispose($hOrig)

GUISetState()

_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, 800, 600)
_GUICtrlCreateAnimGIF("9.gif", 150, 50, 285, 280, -1, -1, False, $hImage, True)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphics)

Please test it with the new UDF. 

I'll update the first post after (done)...

 

Edited by Nine
Removed attachment. Refer to 1st post.
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...