Ejemplo n.º 1
0
        private void GradientGenerator_DoWork(object sender, DoWorkEventArgs e)
        {
            GrayBitmap asyncImage = (GrayBitmap)e.Argument;

            try
            {
                if (asyncImage.Gradient.Bitmap == null)
                {
                    // Don't step through this code with an Locals or Auto
                    // window opened at all. VS will crash the background thread.
                    timer.Start();
                    asyncImage.Gradient.GenerateGradientBitmap(new ProgressCallback(GradientGenerator.ReportProgress));
                    timer.Stop();
                    e.Result = asyncImage.Gradient;
                }
            }
            catch (Exception ex)
            {
                e.Result = ex;
            }
            finally
            {
                asyncImage.Bitmap.Dispose();
            }
        }
 /// <summary>
 /// Clones this object so it can be safely read from another thread.
 /// </summary>
 /// <remarks>
 /// The clone will point to the original gray image.
 /// </remarks>
 public virtual GradientBitmap Clone(GrayBitmap newClonedGrayImage)
 {
     GradientBitmap clone = new GradientBitmap(newClonedGrayImage);
     clone.maximumGradientValue = this.maximumGradientValue;
     if (this.bitmap != null)
         clone.bitmap = (Bitmap)this.bitmap.Clone();
     return clone;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Instantiates a <see cref="GradientBitmap"/> class.
 /// </summary>
 public GradientBitmap(GrayBitmap original)
 {
     if (original == null)
     {
         throw new ArgumentNullException("original");
     }
     this.grayBitmap = original;
     Reset();
 }
Ejemplo n.º 4
0
 public GrayBitmap Clone()
 {
     GrayBitmap clone = new GrayBitmap();
     if (bitmap != null)
         clone.bitmap = (Bitmap)bitmap.Clone();
     if (gradient != null)
         clone.gradient = gradient.Clone(clone);
     clone.maximumGrayValue = maximumGrayValue;
     return clone;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Clones this object so it can be safely read from another thread.
        /// </summary>
        /// <remarks>
        /// The clone will point to the original gray image.
        /// </remarks>
        public virtual GradientBitmap Clone(GrayBitmap newClonedGrayImage)
        {
            GradientBitmap clone = new GradientBitmap(newClonedGrayImage);

            clone.maximumGradientValue = this.maximumGradientValue;
            if (this.bitmap != null)
            {
                clone.bitmap = (Bitmap)this.bitmap.Clone();
            }
            return(clone);
        }
Ejemplo n.º 6
0
        private void FileLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            FileLoadingParams fileLoadingParams = (FileLoadingParams)e.Argument;

            timer.Start();
            GrayBitmap img = new GrayBitmap();
            string     segmentationPoints;

            using (Stream file = fileLoadingParams.FileStream)
                img.Load(file, out segmentationPoints, new ProgressCallback(FileLoader.ReportProgress));
            timer.Stop();

            e.Result = new FileLoadingResult(img, segmentationPoints);
        }
Ejemplo n.º 7
0
        public GrayBitmap Clone()
        {
            GrayBitmap clone = new GrayBitmap();

            if (bitmap != null)
            {
                clone.bitmap = (Bitmap)bitmap.Clone();
            }
            if (gradient != null)
            {
                clone.gradient = gradient.Clone(clone);
            }
            clone.maximumGrayValue = maximumGrayValue;
            return(clone);
        }
Ejemplo n.º 8
0
        private void FileLoader_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            FileLoadingResult result = (FileLoadingResult)e.Result;

            Status = null;
            lblLastOperationTime.Text = timer.Elapsed.ToString();

            if (result.GrayImage != null)
            {
                image = result.GrayImage;
                tbSegmentPoints.Text = result.SegmentationPoints;
                // Display the image.
                boxImage.BackgroundImage    = image.Bitmap;
                boxImage.Image              = PrepareOverlay();
                boxGradient.BackgroundImage = image.Gradient.Bitmap;
                boxGradient.Image           = boxImage.Image;

                // Enable toolbar buttons
                //btnShowGradient.Enabled = true;
                btnSaveFile.Enabled = true;

                // Size the application window appropriately.
                Width  += boxImage.BackgroundImage.Width - boxImage.Width;
                Height += boxImage.BackgroundImage.Height - boxImage.Height;

                // Start generating the gradient right away
                GenerateGradient();

                tabControl1.SelectTab(tabImage);
            }
            else if (result.Exception != null)
            {
                if (MessageBox.Show(this, result.Exception.ToString(), "Error during image load.",
                                    MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    GenerateGradient();
                }
            }
        }
 /// <summary>
 /// constructor for intelligent scissors. 
 /// </summary>
 /// <param name="image">the image you are oging to segment.  has methods for getting gradient information</param>
 /// <param name="overlay">an overlay on which you can draw stuff by setting pixels.</param>
 public DijkstraScissors(GrayBitmap image, Bitmap overlay)
     : base(image, overlay)
 {
 }
Ejemplo n.º 10
0
 public DijkstraScissors(GrayBitmap image, Bitmap overlay) : base(image, overlay)
 {
 }
Ejemplo n.º 11
0
 public SimpleScissors(GrayBitmap image, Bitmap overlay)
     : base(image, overlay)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// constructor for SimpleScissors.
 /// </summary>
 /// <param name="image">the image you are going to segment including methods for getting gradients.</param>
 /// <param name="overlay">a bitmap on which you can draw stuff.</param>
 public SimpleScissors(GrayBitmap image, Bitmap overlay) : base(image, overlay)
 {
 }
 public StraightScissors(GrayBitmap image, Bitmap overlay)
     : base(image, overlay)
 {
 }
Ejemplo n.º 14
0
 public FileLoadingResult(GrayBitmap grayImage, string segmentationPoints)
 {
     this.GrayImage = grayImage;
     this.SegmentationPoints = segmentationPoints;
     this.Exception = null;
 }
Ejemplo n.º 15
0
 public FileLoadingResult(Exception ex)
 {
     this.Exception = ex;
     this.SegmentationPoints = null;
     this.GrayImage = null;
 }
Ejemplo n.º 16
0
        private void FileLoader_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            FileLoadingResult result = (FileLoadingResult)e.Result;
            Status = null;
            lblLastOperationTime.Text = timer.Elapsed.ToString();

            if (result.GrayImage != null)
            {
                image = result.GrayImage;
                tbSegmentPoints.Text = result.SegmentationPoints;
                // Display the image.
                boxImage.BackgroundImage = image.Bitmap;
                boxImage.Image = PrepareOverlay();
                boxGradient.BackgroundImage = image.Gradient.Bitmap;
                boxGradient.Image = boxImage.Image;

                // Enable toolbar buttons
                //btnShowGradient.Enabled = true;
                btnSaveFile.Enabled = true;

                // Size the application window appropriately.
                Width += boxImage.BackgroundImage.Width - boxImage.Width;
                Height += boxImage.BackgroundImage.Height - boxImage.Height;

                // Start generating the gradient right away
                GenerateGradient();

                tabControl1.SelectTab(tabImage);
            }
            else if (result.Exception != null)
            {
                if (MessageBox.Show(this, result.Exception.ToString(), "Error during image load.",
                    MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                    GenerateGradient();
            }
        }
Ejemplo n.º 17
0
        private void FileLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            FileLoadingParams fileLoadingParams = (FileLoadingParams)e.Argument;

            timer.Start();
            GrayBitmap img = new GrayBitmap();
            string segmentationPoints;
            using (Stream file = fileLoadingParams.FileStream)
                img.Load(file, out segmentationPoints, new ProgressCallback(FileLoader.ReportProgress));
            timer.Stop();

            e.Result = new FileLoadingResult(img, segmentationPoints);
        }
Ejemplo n.º 18
0
 protected Scissors(GrayBitmap image, Bitmap overlay)
 {
     Image   = image;
     Overlay = overlay;
 }
 public StraightScissors(GrayBitmap image, Bitmap overlay) : base(image, overlay)
 {
 }
 /// <summary>
 /// Instantiates a <see cref="GradientBitmap"/> class.
 /// </summary>
 public GradientBitmap(GrayBitmap original)
 {
     if (original == null) throw new ArgumentNullException("original");
     this.grayBitmap = original;
     Reset();
 }
Ejemplo n.º 21
0
 protected Scissors(GrayBitmap image, Bitmap overlay)
 {
     Image = image;
     Overlay = overlay;
 }
Ejemplo n.º 22
0
 public FileLoadingResult(GrayBitmap grayImage, string segmentationPoints)
 {
     this.GrayImage          = grayImage;
     this.SegmentationPoints = segmentationPoints;
     this.Exception          = null;
 }