Ejemplo n.º 1
0
        public static void Animate(Image image, EventHandler onFrameChangedHandler)
        {
            // must be non-null and contain animation time frames
            if (!CanAnimate(image))
            {
                return;
            }

            // is animation already in progress ?
            if (ht.ContainsKey(image))
            {
                return;
            }

            PropertyItem item = image.GetPropertyItem(0x5100); // FrameDelay in libgdiplus

            byte[] value = item.Value !;
            int[]  delay = new int[(value.Length >> 2)];
            for (int i = 0, n = 0; i < value.Length; i += 4, n++)
            {
                int d = BitConverter.ToInt32(value, i) * 10;
                // follow worse case (Opera) see http://news.deviantart.com/article/27613/
                delay[n] = d < 100 ? 100 : d;
            }

            AnimateEventArgs aea    = new AnimateEventArgs(image);
            WorkerThread     wt     = new WorkerThread(onFrameChangedHandler, aea, delay);
            Thread           thread = new Thread(new ThreadStart(wt.LoopHandler));

            thread.IsBackground = true;
            aea.RunThread       = thread;
            ht.Add(image, aea);
            thread.Start();
        }
Ejemplo n.º 2
0
        public static void StopAnimate(Image image, EventHandler onFrameChangedHandler)
        {
            if (image == null)
            {
                return;
            }

            if (ht.ContainsKey(image))
            {
                AnimateEventArgs evtArgs = (AnimateEventArgs)ht[image] !;
                evtArgs.RunThread !.Abort();
                ht.Remove(image);
            }
        }
Ejemplo n.º 3
0
        public static void StopAnimate(Image image, EventHandler onFrameChangedHandler)
        {
            if (image == null)
            {
                return;
            }

            if (ht.ContainsKey(image))
            {
                AnimateEventArgs evtArgs = (AnimateEventArgs)ht[image] !;
#pragma warning disable SYSLIB0006 // https://github.com/dotnet/runtime/issues/39405
                evtArgs.RunThread !.Abort();
#pragma warning restore SYSLIB0006
                ht.Remove(image);
            }
        }
Ejemplo n.º 4
0
 public WorkerThread(EventHandler frmChgHandler, AnimateEventArgs aniEvtArgs, int[] delay)
 {
     frameChangeHandler = frmChgHandler;
     animateEventArgs   = aniEvtArgs;
     this.delay         = delay;
 }
Ejemplo n.º 5
0
        // this method avoid checks that aren't requied for UpdateFrames()
        private static void UpdateImageFrame(Image image)
        {
            AnimateEventArgs aea = (AnimateEventArgs)ht[image] !;

            image.SelectActiveFrame(FrameDimension.Time, aea.GetNextFrame());
        }
Ejemplo n.º 6
0
		public static void Animate (Image image, EventHandler onFrameChangedHandler)
		{
			// must be non-null and contain animation time frames
			if (!CanAnimate (image))
				return;

			// is animation already in progress ?
			if (ht.ContainsKey (image))
				return;

			PropertyItem item = image.GetPropertyItem (0x5100); // FrameDelay in libgdiplus
			byte[] value = item.Value;
			int[] delay = new int [(value.Length >> 2)];
			for (int i=0, n=0; i < value.Length; i += 4, n++) {
				int d = BitConverter.ToInt32 (value, i) * 10;
				// follow worse case (Opera) see http://news.deviantart.com/article/27613/
				delay [n] = d < 100 ? 100 : d;
			}

			AnimateEventArgs aea = new AnimateEventArgs (image);
			WorkerThread wt = new WorkerThread (onFrameChangedHandler, aea, delay);
			Thread thread = new Thread (new ThreadStart (wt.LoopHandler));
			thread.IsBackground = true;
			aea.RunThread = thread;
			ht.Add (image, aea);
			thread.Start ();
		}
Ejemplo n.º 7
0
		public WorkerThread (EventHandler frmChgHandler, AnimateEventArgs aniEvtArgs, int[] delay)
		{
			frameChangeHandler = frmChgHandler;
			animateEventArgs = aniEvtArgs;
			this.delay = delay;
		}