1 Attachment(s)
[twinBASIC] - Simple Animated GIF Player with WinRT / BitmapDecoder & Multi-Threading
I have just translated my previous VB6 GIF Player project to twinBASIC 64-bit and also introduced multi-threading capabilities to take advantage of this feature exclusive to tB. Now each delegate will complete its work on a new thread.
Here is the demo project: Attachment 194626 (download the test GIFs from the VB6 thread linked above as they were too big to include in the attachment).
1 Attachment(s)
Re: [twinBASIC] - Simple Animated GIF Player with WinRT / BitmapDecoder & Multi-Threa
This is another twist on the animated GIF player above only instead of manually decoding the frames and rendering them individually with a Timer, this time all the nitty-gritty details are abstracted by a XAML Image control hosted inside a regular PictureBox. This makes the code much shorter and cleaner:
Code:
Private WithEvents cImage As cImage, bFlag As Boolean
Private Sub Form_Load()
Set cImage = New cImage
If cImage.InitIsland(picImage.hWnd) Then cImage.LoadImage "https://www.vbforums.com/images/ieimages/2025/03/2.gif": bFlag = Not bFlag
End Sub
Private Sub Form_Click()
cImage.LoadImage IIf(bFlag, "https://media.githubusercontent.com/media/SixLabors/ImageSharp/main/tests/Images/Input/Gif/cheers.gif", "https://www.vbforums.com/images/ieimages/2025/03/2.gif")
bFlag = Not bFlag
End Sub
Private Sub cImage_ImageOpened(imgWidth As Long, imgHeight As Long)
With picImage
.Move .Left, .Top, .ScaleX(imgWidth, vbPixels, .ScaleMode), .ScaleY(imgHeight, vbPixels, .ScaleMode)
End With
End Sub
Private Sub cImage_ImageFailed(sErrorMessage As String)
MsgBox sErrorMessage, vbOKOnly + vbExclamation, App.Title
End Sub
Private Sub picImage_Resize()
With picImage
Width = .Width + (Width - ScaleWidth) + .Left * 2
Height = .Height + (Height - ScaleHeight) + .Top * 2
End With
End Sub
Using the {Binding} markup extension, the Image control's Source property is bound to a Uri object thus enabling it to play GIFs both from a web address or a local file. Additional features include:
- Click on the image to Stop/Start the animation
- Click on the form to switch between two sample GIFs loaded from different URLs
- The control raises events to signal whether the image was opened successfully or failed (to due to an incorrect file format or URL address)
Here is the demo project: Attachment 195187 (compile the executable to run the demo)
Requirements: Windows 10 or later!
Re: [twinBASIC] - Simple Animated GIF Player with WinRT / BitmapDecoder & Multi-Threa
Need pictures or the picture is incomplete.
Re: [twinBASIC] - Simple Animated GIF Player with WinRT / BitmapDecoder & Multi-Threa
Give it a whirl if you want the full experience, not much point in taking a picture of an animated GIF! :D
Re: [twinBASIC] - Simple Animated GIF Player with WinRT / BitmapDecoder & Multi-Threa