Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » Creating Animated GIF Images VB.NET 2008


Creating Animated GIF Images VB.NET 2008

Reply
  #1 (permalink)  
Old 06-17-08, 08:38 PM
mattthetoadwart mattthetoadwart is offline
New Member
 
Join Date: Jun 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Creating Animated GIF Images VB.NET 2008

I'm working on a program that is able to create Animated GIF images from still images. The way I have set it up is that you will open still images into a Listbox via an Open File Dialog. Then you will type a time frame for the GIF to change into a Textbox. You then select a location to save the GIF via a Save File Dialog. When you click Save, the location appears in a Textbox. Finally you click a Button and the program creates the GIF Image in the selected location.

Only 1 Problem... I don't know the code to create the Animated GIF Image!



If anyone knows the code to do this, could you please tell me what is by replying to this message.

Thank You.


Matthew Blanch (also know as matt the toadwart).
Reply With Quote
  #2 (permalink)  
Old 06-18-08, 09:49 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Here is what you are looking for (NGIF animated GIF encoder for .NET):

http://www.codeproject.com/KB/GDI-plus/NGif.aspx


Pete
__________________
Reply With Quote
  #3 (permalink)  
Old 06-18-08, 05:47 PM
mattthetoadwart mattthetoadwart is offline
New Member
 
Join Date: Jun 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I don't think this is what I'm looking for. It appears to be for C#. I only program in Visual Basic .NET.

Is there a version for VB.NET?


Matt B
Reply With Quote
  #4 (permalink)  
Old 06-18-08, 11:38 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
You can reference the library in VB.NET as well as C#. That's the beauty of the .NET Framework. Here is an example in VB.NET:

vbnet Code:
  1. Imports System
  2. Imports System.Drawing
  3. Imports System.Drawing.Imaging
  4. Imports Gif.Components
  5.  
  6. Public Class Form1
  7.  
  8.     Public csProjectPath As String
  9.  
  10.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  11.         Dim lsImageName As String
  12.         Dim laFrames() As String = {"01.png", "02.png", "03.png"}
  13.         csProjectPath = Application.StartupPath
  14.         csProjectPath = Replace(csProjectPath, "\bin\Debug", "")
  15.         csProjectPath = Replace(csProjectPath, "\bin\Release", "")
  16.         For Each lsImageName In laFrames
  17.             lstFrames.Items.Add(csProjectPath & "\images\" & lsImageName)
  18.         Next
  19.         If lstFrames.Items.Count > 0 Then
  20.             lstFrames.SelectedIndex = 0
  21.             pbFrame.ImageLocation = lstFrames.Items.Item(0).ToString
  22.         End If
  23.     End Sub
  24.  
  25.     Private Sub lstFrames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFrames.SelectedIndexChanged
  26.         pbFrame.ImageLocation = lstFrames.SelectedItem
  27.     End Sub
  28.  
  29.     Private Sub btnAnimate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnimate.Click
  30.         Dim lsOutputFilePath As String = csProjectPath & "\images\test.gif"
  31.         Dim loAGifEncoder As New AnimatedGifEncoder()
  32.         loAGifEncoder.Start(lsOutputFilePath)
  33.         loAGifEncoder.SetDelay(500)
  34.         '-1:no repeat,0:always repeat
  35.         loAGifEncoder.SetRepeat(0)
  36.         Dim i As Integer = 0
  37.         Dim count As Integer = lstFrames.Items.Count
  38.         While i < count
  39.             loAGifEncoder.AddFrame(Image.FromFile(lstFrames.Items.Item(i)))
  40.             i += 1
  41.         End While
  42.         loAGifEncoder.Finish()
  43.         Dim gifDecoder As New GifDecoder()
  44.         gifDecoder.Read(lsOutputFilePath)
  45.         i = 0
  46.         count = gifDecoder.GetFrameCount()
  47.         While i < count
  48.             Dim frame As Image = gifDecoder.GetFrame(i)
  49.             frame.Save(lsOutputFilePath + Guid.NewGuid().ToString() + ".png", ImageFormat.Png)
  50.             i += 1
  51.         End While
  52.         pbAnimated.ImageLocation = lsOutputFilePath
  53.     End Sub
  54.  
  55. End Class

Here is how it looks:

Animated_GIF_Sample_Application.jpg

Sample VB.NET Project is attached in a zip file.


Pete
Attached Files
File Type: zip NGif-VB.zip (111.8 KB, 2059 views)
__________________
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
onclick start animated gif cedric813 JavaScript 3 11-07-09 09:04 PM
Creating TRULY Transparent / Translucent Images? nova912 The Lounge 0 11-12-06 01:16 AM
Firefox issue with animated gif mysticalmaze PHP 0 07-22-05 08:56 PM
Creating Dynamic Images With PHP cdphreaker PHP 0 02-20-05 03:26 PM


All times are GMT -5. The time now is 02:17 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.