I'm using the below to grab an animated gif off the web. However, upon saving this to disk, I lose the frames in the gif, and it no longer animates. Not sure whether the problem is in the below method, or whether it's when I'm saving it, but any feedback on why the below wouldn't work appreciated. The method is working - just not creating a proper animated gif file.
public Image getImage(String url)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();
return Image.FromStream(stream, true, true);
}
Image im = getImage(url)
im.Save(pth,ImageFormat.Gif);
Search for a GIF on Google Images via your mobile browser. Once found, tap on the GIF to open it as much as possible (so you are not viewing it in search results). Hold your finger down on the GIF until a menu pops up. From the menu, click on “Save Image.”
Download and install the GIPHY app from the Google Play Store. Use the search bar at the top of the screen to look for a GIF image. Out of all the relevant results, tap on the one you'd like to download. Press and hold on the GIF image and press Yes to save the image to your device.
You should not create an Image
from the stream (it will only store the first frame). Instead, you should write the contents of the Stream
directly to disk using, for example, the Stream.CopyTo
method to copy the content to a FileStream
you created for the destination file.
using (Stream stream = httpWebReponse.GetResponseStream())
using (FileStream fs = File.Create(path))
{
stream.CopyTo(fs);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With