利用System.Drawing.ImageAnimator类实现GIF图标显示

public class GMapMarkerImage : GMapMarker
{
    private Image image;
    private bool currentlyAnimating;

    public GMapMarkerImage(PointLatLng pos, Image image) : base(pos)
    {
        Size = new Size(image.Width, image.Height);
        Offset = new Point(-Size.Width / 2, -Size.Height / 2);
        this.image = image;
    }

    protected GMapMarkerImage(SerializationInfo info, StreamingContext context) : base(info, context)
    {
    }
    private bool isAnimateImage()
    {
        if (image == null)
            return false;
        return ImageAnimator.CanAnimate(image);
    }
    public void AnimateImage()
    {
        if (!currentlyAnimating)
        {
            ImageAnimator.Animate(image, new EventHandler(this.OnFrameChanged));
            currentlyAnimating = true;
        }
    }

    private void OnFrameChanged(object sender, EventArgs e)
    {
        
    }

    public override void OnRender(Graphics g)
    {
        if (image == null)
        {
            return;
        }
        if (isAnimateImage())
        {
            AnimateImage();
            //更新到下一帧
            ImageAnimator.UpdateFrames();
        }
         rect = new Rectangle(LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
        g.DrawImage(image, rect);
    }
}

定时器设置为300毫秒

private void timer1_Tick(object sender, EventArgs e)
{
    _mmapControl.Refresh();
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-05-24
猜你喜欢
  • 2021-07-24
  • 2021-10-22
  • 2021-06-19
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案