PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] Why assigning an Image object containing gif to a new instance of Bitmap, breaks the gif

 July 18, 2022     .net, bitmap, c#, gif, winforms     No comments   

Issue

An Image object contains a gif file and if saved to disk and opened, the gif is displaying properly. However, if a Bitmap object is created from the image instance, and saved, the gif no longer works:

 WebClient client = new WebClient();
 client.DownloadFile(new Uri("http://www.ajaxload.info/images/exemples/25.gif"), "25.gif");

 Image original = Image.FromFile("25.gif");
 original.Save("25-WorksFine.gif", ImageFormat.Gif);

 Bitmap bmp = new Bitmap(original);
 bmp.Save("25-Broken.gif", ImageFormat.Gif);

Solution

Image.FromFile uses native GDI+ to load a file using an appropriate decoder

new Bitmap(Image) creates a drawing surface(Graphics) of the size of the image then draws the image on it using Graphics.DrawImage

I suppose in this last case no animation is preserved



Answered By - Dmitry
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing