Search code examples
.netc#-2.0pictureboxanimated-giftemporary-files

How to load animated gif to picturebox and then delete original file?


I wonder how can I load animated gif to picturebox and than delete original file? I know how to achieve this with simple bitmap ( http://support.microsoft.com/kb/814675/en-us?fr=1 ), but how to do this with moving gif? And if there is some special class or methods for this, is there some way how to determine, if the temp file (from which I load picture) is simple bitmap or moving gif?


Solution

  • In the end, I used slution based on Hans suggestion. First, I loaded gif to Image with FromStream method from file. Than I loaded MemoryStream with Image and convert it to byte array. Now I can close both streams. After this, I used TypeConverter to recover Image from byte array. I know, its not very elegant, but it works.

    Image imgTemp = Image.FromStream(ms);
    imgTemp.Save(byteStream, imgTemp.RawFormat);
    byte[] temparray = byteStream.ToArray();
    TypeConverter tc = TypeDescriptor.GetConverter(typeof(Image));
    Image newImage = (Image)tc.ConvertFrom(temparray);
    this.m_Image.Image = null;
    this.m_Image.Image = newImage;