[saving animated GIF] Help...

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 41
Reputation: murid is an unknown quantity at this point 
Solved Threads: 1
murid murid is offline Offline
Light Poster

[saving animated GIF] Help...

 
0
  #1
Jun 16th, 2009
if I want to send an animated GIF format picture, how do I save the picture in destination folder?
I already using "System.Drawing.Imaging.ImageFormat.gif", but the GIF picture no longer animated, it become like JPEG format.
another help please...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: [saving animated GIF] Help...

 
0
  #2
Jun 16th, 2009
Could you please post your current image saving code. Thanks!
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: [saving animated GIF] Help...

 
1
  #3
Jun 16th, 2009
Never mind the code. Here's a (generic) function to save byte array to a file (VB.NET 2005 and newer)
  1. Public Function SaveFile(ByVal FileName As String, ByRef Buffer() As Byte, ByVal OverWrite As Boolean) As Boolean
  2. ' Save a bytearray to a file
  3. ' Returns True if file is saved, otherwise returns false
  4. ' Notice: Exception handling is missing!
  5. If My.Computer.FileSystem.FileExists(FileName) Then
  6. If OverWrite Then
  7. My.Computer.FileSystem.DeleteFile(FileName)
  8. My.Computer.FileSystem.WriteAllBytes(FileName, Buffer, False)
  9. Return True
  10. Else
  11. ' Don't save, file exists
  12. Return False
  13. End If
  14. Else
  15. My.Computer.FileSystem.WriteAllBytes(FileName, Buffer, False)
  16. Return True
  17. End If
  18.  
  19. End Function
And you call it (example):
  1. If SaveFile("C:\my.gif", ByteBuffer, False) Then
  2. MessageBox.Show("File saved successfully", "Save File", MessageBoxButtons.OK, MessageBoxIcon.Information)
  3. Else
  4. MessageBox.Show("File exists or could not be written", "Save File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  5. End
Another example: SaveFile("C:\my.gif", ByteBuffer, True) saves the file and overwrites the file if it exists.

One thing to be careful is array indexing which starts from the zero. If you declare an array Buffer(4) As Byte , you'll have an array with five bytes (Buffer(0), Buffer(1),...Buffer(4)). Forgetting this can easily lead to "off-by-one" errors and hard-to-catch errors.

HTH

Use this code to save animated GIF. It might be possible that "normal" .NET's image saving methods (or file formats to be precise) do not support animated GIFs. Saving an animated GIF as "raw" data is 100% sure way to ensure it is saved correctly.
Last edited by Teme64; Jun 16th, 2009 at 6:06 am. Reason: Added comment about animated GIFs
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 41
Reputation: murid is an unknown quantity at this point 
Solved Threads: 1
murid murid is offline Offline
Light Poster

Re: [saving animated GIF] Help...

 
0
  #4
Jun 17th, 2009
thanks for the code...
I'll try it first...
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 41
Reputation: murid is an unknown quantity at this point 
Solved Threads: 1
murid murid is offline Offline
Light Poster

Re: [saving animated GIF] Help...

 
0
  #5
Jun 17th, 2009
  1. Dim PACKET_SIZE As UInt16 = 4096
  2. Dim Reader As BinaryReader
  3. Dim ReadBuffer(PACKET_SIZE - 1) As Byte
  4. Dim NData As Int32
  5. Dim MStream As MemoryStream
  6. Dim LData As Int32
  7.  
  8. Reader = New BinaryReader(clientSocket.GetStream)
  9. ' Read Length of data (Int32)
  10. NData = Reader.ReadInt32
  11. ' Now comes the data, save it in a memory stream
  12. MStream = New MemoryStream
  13. While NData > 0
  14. LData = clientSocket.GetStream.Read(ReadBuffer, 0, PACKET_SIZE)
  15. MStream.Write(ReadBuffer, 0, LData)
  16. NData -= LData
  17. End While
  18.  
  19. If SaveFile("C:\my.gif", ReadBuffer, False) Then
  20. MessageBox.Show("File saved successfully", "Save File", MessageBoxButtons.OK, MessageBoxIcon.Information)
  21. Else
  22. MessageBox.Show("File exists or could not be written", "Save File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  23. End If

it's my code went socket receive picture n save it.
still cannot save animated GIF picture.
the code are working perfectly, but the saved picture can't move...

I'm not changing anything for the function...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: [saving animated GIF] Help...

 
0
  #6
Jun 17th, 2009
Actually you're saving incoming data to the memory stream, not in the temporary byte buffer. You should save the content of the memory stream.

Change this single line
  1. If SaveFile("C:\my.gif", MStream.ToArray(), False) Then
ToArray method returns the content of the whole memory stream as a byte array.

And one reminder again. Close and dispose streams, sockets etc. after using them

If the code still doesn't work after making the code change above, could you please attach your original animated gif image. Not sure if I have in hand any easily findable animated gif to test with
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 41
Reputation: murid is an unknown quantity at this point 
Solved Threads: 1
murid murid is offline Offline
Light Poster

Re: [saving animated GIF] Help...

 
0
  #7
Jul 3rd, 2009
Your code working GREAT !!
Finally I found what's wrong...
my mistake is I save the selected GIF picture to JPG format before displaying it...
by doing that, I send and save the JPG format instead of the GIF file...
that's why my GIF never move...

sorry to trouble U.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: [saving animated GIF] Help...

 
0
  #8
Jul 3rd, 2009
Your code working GREAT !!
Great!

sorry to trouble U
There wasn't any trouble
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC