question

sharonglipman-9594 avatar image
0 Votes"
sharonglipman-9594 asked sharonglipman-9594 commented

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

 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.

dotnet-csharpwindows-forms
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you attach both images here (first downloaded from the internet, second saved from paint) so we can take a look?

1 Vote 1 ·

I found a solution how to do it. To show the solution or to delete the question ?

0 Votes 0 ·
Paul-5034 avatar image Paul-5034 sharonglipman-9594 ·

If you feel like other people may run into the same issue feel free to post the solution.

1 Vote 1 ·

1 Answer

Castorix31 avatar image
1 Vote"
Castorix31 answered sharonglipman-9594 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

And how can I add a progressbar in async so it will not freeze the form1 to report to the progressbar1 the progress of downloading of each file ?

I asked it here in a new question few minutes ago with my working code :

https://docs.microsoft.com/en-us/answers/questions/584235/how-to-report-to-a-progressbar-when-downloading-fi.html

0 Votes 0 ·