private void showContourButton_Click(object sender, EventArgs e) { if (this.imageButton.Image == null) { return; } if (template == null) { template = this.imageButton.Image; } DateTime start = DateTime.Now; ContourImage ci = new ContourImage(template, null); ci.ProcessImage(); processed = ci.ProcessedImage; TimeSpan t = DateTime.Now - start; int ms = (int)t.TotalMilliseconds; this.timeLabel.Text = ms.ToString(); this.imageButton.Image = processed; }
/// <summary> /// Processes and enqueues the given image. /// </summary> /// <param name="img"></param> private void Enqueue(ContourImage img) { //Log.WriteLine("{ " + string.Format("Enqueue({0})", img.ToString())); // Wait while the queue contains enough items. queueFullSemaphore.WaitOne(); if (img != null) { img.ProcessImage(); } // Enqueue the processed image. //Log.WriteLine("- Enqueue() Enqueue"); queue.Enqueue(img); #region Add the image path to a separate list; save that list to the Registry if (queuedImagePaths != null) { lock (queuedImagePaths) { if (img.HasContour) { // True contour images should be loaded last. queuedImagePaths.Add(img.Path); } else { // Images without a contour should be loaded first. queuedImagePaths.Insert(0, img.Path); } if (queuedImagePaths.Count >= queueLength) { SaveImagePaths(); } } } #endregion queueEmptySemaphore.Release(); #if true /* Continue at the lower thread priority as soon as the first image has been loaded. * This assumes that a) we need only one image or b) we can easily load more images on demand. * This works fine if enough images can be loaded from the saved images list. * See LoadImagePaths(). */ ReduceThreadPriority(); #endif //Log.WriteLine("} Enqueue()"); }