GMap.NET 显示GIF图标的定制

利用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();
}

 

posted @ 2017-05-20 15:21  joe62  阅读(720)  评论(0编辑  收藏  举报