private static void SaveImages(ThreadContext threadContext) { try { ImageWrap image; Bitmap bmp; float progress = 0; for (int i = 0; i < threadContext.Images.Count; i++) { if (threadContext.IsExit) { threadContext.Progress = 100; break; } if (threadContext.Images[i] != null) { Thread.Sleep(5); image = (ImageWrap)threadContext.Images[i]; if (image != null) { bmp = image.CopyImage(); if (bmp != null) { try { bmp.Save(threadContext.Path + "\\" + i + ".dat", ImageFormat.Jpeg); } finally { bmp.Dispose(); } } } progress += 1; threadContext.Progress = (int)(progress / threadContext.Images.Count * 100); } } } catch (Exception e) { System.Console.Out.WriteLine("SaveImages Exception: {0}", e); } }
public bool Stop(int handle) { lock (mThreadContexts.SyncRoot) { ThreadContext threadContext = (ThreadContext)mThreadContexts["ThreadContext_" + handle]; if (threadContext != null) { threadContext.IsExit = true; if (threadContext.CurThread.ThreadState == System.Threading.ThreadState.Suspended) { threadContext.CurThread.Resume(); } return(true); } } return(false); }
private void ThreadPlay(object obj) { ThreadContext threadContext = (ThreadContext)obj; try { if (threadContext.HWnd != IntPtr.Zero && !threadContext.IsExit) { if (threadContext.Path != null && !threadContext.Path.Equals("")) { PlayPath(threadContext); } else { if (threadContext.Images == null) { threadContext.Images = ToArray(); } if (threadContext.Images.Count > 0 && !threadContext.IsExit) { PlayImages(threadContext); } } } lock (mThreadContexts.SyncRoot) { mThreadContexts.Remove("ThreadContext_" + threadContext.Handle); } } finally { if (threadContext.Progress != 100) { threadContext.Progress = 100; } threadContext.Dispose(); } }
private void ThreadSave(object obj) { ThreadContext threadContext = (ThreadContext)obj; try { if (!threadContext.IsExit) { if (threadContext.Images == null) { threadContext.Images = ToArray(); } if (threadContext.Images.Count > 0) { SaveImages(threadContext); } else { threadContext.Progress = 100; } } lock (mThreadContexts.SyncRoot) { mThreadContexts.Remove("ThreadContext_" + threadContext.Handle); } } finally { if (threadContext.Progress != 100) { threadContext.Progress = 100; } threadContext.Dispose(); } }
public int Play(string path, IntPtr hWnd) { ThreadContext threadContext; if (path != null && !path.Equals("")) { threadContext = new ThreadContext(path, hWnd); } else { threadContext = new ThreadContext(hWnd); } threadContext.OnRecordProgress += new RECORD_PROGRESS(DoRecordProgress); Thread playThread = new Thread(new ParameterizedThreadStart(ThreadPlay)); threadContext.CurThread = playThread; mThreadContexts.Add("ThreadContext_" + threadContext.Handle, threadContext); playThread.Start(threadContext); return(threadContext.Handle); }
private static void PlayPath(ThreadContext threadContext) { if (threadContext.Path != null && !threadContext.Path.Equals("")) { if (threadContext.HWnd != IntPtr.Zero) { try { win32.RECT rect = new win32.RECT(); win32.GetClientRect(threadContext.HWnd, ref rect); Graphics graphics = threadContext.CurGraphics; if (graphics == null) { return; } string[] files = Directory.GetFiles(threadContext.Path, "*.dat"); if (files != null && files.Length > 0) { Bitmap bmp; float progress = 0; Array.Sort(files, new FileComparer(true)); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < files.Length; i++) { if (threadContext.IsExit) { threadContext.Progress = 100; break; } bmp = new Bitmap(files[i]); if (bmp != null) { try { graphics.DrawImage(bmp, 0, 0, rect.right, rect.bottom); } finally { bmp.Dispose(); } } progress += 1; threadContext.Progress = (int)(progress / files.Length * 100); sw.Stop(); int n = 40 - (int)sw.ElapsedMilliseconds; if (n > 0) { Thread.Sleep(n); } sw.Reset(); sw.Start(); } sw.Stop(); } } catch (Exception e) { System.Console.Out.WriteLine("PlayPath Exception: {0}", e); } } } }
private static void PlayImages(ThreadContext threadContext) { if (threadContext.HWnd != IntPtr.Zero) { try { win32.RECT rect = new win32.RECT(); win32.GetClientRect(threadContext.HWnd, ref rect); Graphics graphics = threadContext.CurGraphics; if (graphics == null) { return; } float progress = 0; Stopwatch sw = new Stopwatch(); sw.Start(); Bitmap bmp; foreach (ImageWrap image in threadContext.Images) { if (threadContext.IsExit) { threadContext.Progress = 100; break; } if (image != null) { bmp = image.CopyImage(); if (bmp != null) { try { graphics.DrawImage(bmp, 0, 0, rect.right, rect.bottom); } finally { bmp.Dispose(); } } } progress += 1; threadContext.Progress = (int)(progress / threadContext.Images.Count * 100); sw.Stop(); int n = 40 - (int)sw.ElapsedMilliseconds; if (n > 0) { Thread.Sleep(n); } sw.Reset(); sw.Start(); } sw.Stop(); } catch (Exception e) { System.Console.Out.WriteLine("PlayImages Exception: {0}", e); } } }