How to DrawImage without losing animation?
pictureBox1.Image = new Bitmap(20, 20);
Graphics g = Graphics.FromImage(pictureBox1.Image);
Image i = Properties.Resources.SuperMario; //Animated GIF; sprite; 20px X 20px
g.DrawImage(i,
new Rectangle(0, 0, 20, 20),
new Rectangle(0, 0, 20, 20),
GraphicsUnit.Pixel);
pictureBox1.Refresh();
The above codes, copies image portion from an animated sprite sheet (GIF format) to PictureBox‘ Image. Unfortunately, the animation is lost.
Thank you in advance.
Load the entire gif in picture box and position it such that only relevant portion is shown in picture box. Thats how sprites work. You don’t have to copy the portion of a particular frame because yes that would obviously lose animation.
Put your picture box inside a panel and then set the location of picture box to the position of sprite element.