How can I download image file using webclient and save it on the hard disk as gif file format ?

sharon glipman 441 Reputation points
2021-10-09T19:01:18.923+00:00
client.DownloadFile(link, @"D:\satImages\satImage" + i + ".gif");
                }
            }

            FileInfo[] fi;
            DirectoryInfo dir1 = new DirectoryInfo(@"D:\satImagess");
            fi = dir1.GetFiles("*.gif");
            for (int i = 0; i < fi.Length; i++)
            {
                myGifList.Add(fi[i].FullName);

            }

            uf.MakeGIF(myGifList, @"D:\satImages\agif\my.gif", 100, true);

The problem is when I download the image files and name them .gif on the hard disk they are not really in gif format or not the gif format I need.

The problem is in the line :

uf.MakeGIF(myGifList, @"D:\satImages\agif\my.gif", 100, true);

It should get List<string> of gifs files names and it does in myGifList but throw me an error say not a gif.

I did some test : I edited some of the downloaded images with paint and in paint saved each image as gif than running the program again this time getting the saved gif files from the paint and it did work fine.

For some reason when I download the images with webclient and save them as gif they are not really gifs or not the right format.
After editing in paint and save them as gif it's working.

So I wonder what is the different between the images I'm downloading and saving them as .gif and the images same images I downloaded but saved them in paint as gifs? paint save them as gif in some other format ? I don't get it.

But after the test I'm sure something is wrong with just naming the images as .gif when downloading them.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,839 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,310 questions
{count} votes

Accepted answer
  1. Castorix31 81,831 Reputation points
    2021-10-09T20:59:08.647+00:00

    You can use a stream to convert the image to GIF

    Test with a .JPG converted to GIF:

                    string sTempPath = System.IO.Path.GetTempPath();
                    sTempPath = String.Concat(sTempPath, "test.gif");
                    using (var wc = new System.Net.WebClient())
                    {
                        using (MemoryStream ms = new MemoryStream(wc.DownloadData("https://image.ibb.co/buLv2e/Little_Girl3.jpg")))
                        {
                            Image img = Image.FromStream(ms, true);
                            img.Save(sTempPath, System.Drawing.Imaging.ImageFormat.Gif);
                        }
                    }
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful