Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Interface and Graphics (http://www.xtremevbtalk.com/-net-interface-and-graphics/)
-   -   Tiled animated gif image in picturebox (http://www.xtremevbtalk.com/-net-interface-and-graphics/327082-tiled-animated-gif-image-picturebox.html)

daluge 05-30-2014 12:10 AM

Tiled animated gif image in picturebox
I noticed that tiling a .gif image as the BackgroundImage of anything does not support the animation, so I came here to ask how would one make this possible? If you could provide the code that would be fantastic.


boops boops 06-06-2014 01:47 AM

3 Attachment(s)
BackgroundImage doesn't animate a GIF anyway -- only the PictureBox.Image does that. But we can get round this using 2 picture boxes, one to play the animated GIF and another to show the tiled background image.

Here's an example. Start with a Form with a picture box (PictureBox1) for showing the tiled image. Don't set the BackgroundImage yet, but set its BackgroundImageLayout to Tile. You can set its Image to whatever you like.

Add a second picture box (PictureBox2) as a "player" for the animated GIF. Set its Image to the animated GIF and its SizeMode to AutoSize.

Add a Timer (Timer1) and set its Interval to 30 or so. The Timer will be used to grab the image from the player, using the DrawToBitmap method. An advantage of DrawToBitmap is that you can hide the source control off-screen or behind another control at runtime while grabbing (but don't use Hide).

Here's the code for the form:

vb.net Code:
Dim tile As Bitmap Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load tile = New Bitmap(PictureBox2.Image.Width, PictureBox2.Image.Height) PictureBox2.Location = New Point(-PictureBox2.Width, -PictureBox2.Height) 'hide PictureBox2 off-screen Timer1.Start() End Sub Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick PictureBox2.DrawToBitmap(tile, PictureBox2.ClientRectangle) PictureBox1.BackgroundImage = tile PictureBox1.Refresh() End Sub

This worked for me with animated GIFs (attached below) for both the tiled BackgroundImage and the Image. The world turns against a chorus of dancing mice.

All times are GMT -6. The time now is 12:58 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.