Esempio n. 1
0
        private void menu_OutputImage_Size_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem c = sender as ToolStripMenuItem;
            string            tag;

            tag = c.Tag.ToString();

            if (tag == "other")
            {
                // Show FormOutputImageSettings
                menu_OutputImag_Settings_Click(null, null);
            }
            else
            {
                ImageAnalyzerObject.OutputImageZoom = int.Parse(tag);

                // 'Check' clicked menu item
                UpdateOutputImageMenuUI();

                // Redraw output image
                if (ImageAnalyzerObject.Output != null)
                {
                    ImageAnalyzerObject.RedrawOutput();
                    picOutput.Image         = ImageAnalyzerObject.Output;
                    lblOutputImageZoom.Text = tag + "  برابر";
                }
            }
        }
Esempio n. 2
0
        private void menu_OutputImage_ShowSubGrid_Click(object sender, EventArgs e)
        {
            ImageAnalyzerObject.Grid.ShowSubGrid = menu_OutputImage_ShowSubGrid.Checked;

            if (ImageAnalyzerObject.Output != null)
            {
                ImageAnalyzerObject.RedrawOutput();
                picOutput.Image = ImageAnalyzerObject.Output;
                DocumentObject.IsDocumentChanged = true;
            }
        }
Esempio n. 3
0
        private void LoadFile(string fileName)
        {
            const string MESSAGE_IMAGE_LOAD_FAILED = "هنگام بارگذاری فایل خطایی رخ داده است، لطفا فایل انتخاب شده را بررسی کنید.";
            const string MESSAGE_FILE_LOADED       = "تصویر بارگذاری شد.";

            Bitmap img         = null;
            bool   imageLoaded = true;

            // Load file
            try {
                DocumentObject.LoadFromFile(fileName);
                img = (Bitmap)DocumentObject.InputImage;
            }
            catch (Exception exp) {
                imageLoaded = false;
                UpdateUI(false, false);
                StaticMethods.ShowErrorMessage(MESSAGE_IMAGE_LOAD_FAILED, exp);
            }

            if (imageLoaded)
            {
                ImageAnalyzerObject.Rest();
                ImageAnalyzerObject.Input           = new Bitmap(img);
                ImageAnalyzerObject.OutputImageZoom = 8;
                LabelManagerObject.DeleteAllLabels(false);

                picInput.Image  = img;
                picOutput.Image = null;

                // Update UI
                UpdateUI(true, false);
                tabControlMain.SelectedIndex = 0;
                lblStatusRight.Text          = MESSAGE_FILE_LOADED;

                // if A ".cpg" file is opened, we should add labels and process it automatically
                if (DocumentObject.IsCpgDocument)
                {
                    ImageAnalyzerObject.OutputImageZoom = DocumentObject.OutputImageZoom;

                    // Start Analyzing
                    menu_Program_StartAnalyze_Click(null, null);

                    // Add Labels
                    LabelManagerObject.AddLabels(DocumentObject.Labels.ToArray());
                }

                //
                UpdateOutputImageMenuUI();
            }
        }
Esempio n. 4
0
        private void menu_Program_SaveOutput_Click(object sender, EventArgs e)
        {
            if (saveOutputFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.Drawing.Imaging.ImageFormat defaultImageFormat;

                // Default image format
                if (saveOutputFileDialog.FilterIndex == 1)
                {
                    defaultImageFormat = System.Drawing.Imaging.ImageFormat.Bmp;
                }
                else if (saveOutputFileDialog.FilterIndex == 2)
                {
                    defaultImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                }
                else if (saveOutputFileDialog.FilterIndex == 3)
                {
                    defaultImageFormat = System.Drawing.Imaging.ImageFormat.Png;
                }
                else
                {
                    defaultImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
                }


                // Save Output Image
                Control.ControlCollection labels;
                labels = (menu_Labeling_ShowLabels.Enabled ? LabelManagerObject.Container.Controls : null);
                try {
                    ImageAnalyzerObject.SaveOutputImage(saveOutputFileDialog.FileName, labels, defaultImageFormat);
                }
                catch (Exception exp) {
                    StaticMethods.ShowErrorMessage("هنگام ذخیره سازی تصویر خطایی رخ داد، لطفا دوباره سعی کنید.", exp);
                }
            }
        }
Esempio n. 5
0
        private void btnCut_Click(object sender, EventArgs e)
        {
            const string MESSAGE_SAVE_ERROR = "هنگام ذخیره سازی قطه تصویر های تولید شده، خطایی رخ داد.";
            const string MESSAGE_NO_OUTPUT  = "ابتدا باید تصویر ورودی پردازش شود.";
            string       fileName;

            Image[,] segments;

            //
            if (ImageAnalyzerObject.Output == null)
            {
                StaticMethods.ShowMessage(MESSAGE_NO_OUTPUT);
                return;
            }

            // Cut Output Image
            segments = ImageAnalyzerObject.CutOutputImage(
                (int)numCutWidth.Value,
                (int)numCutHeight.Value,
                txtFooter.Text,
                picFooterColor.BackColor,
                fontDialog.Font,
                (int)numBorderSize.Value,
                LabelManagerObject.Container.Controls);

            // Set image segments file format
            System.Drawing.Imaging.ImageFormat imgFormat;
            if (cmbFileType.SelectedIndex == 0)
            {
                imgFormat = System.Drawing.Imaging.ImageFormat.Png;
            }
            else if (cmbFileType.SelectedIndex == 1)
            {
                imgFormat = System.Drawing.Imaging.ImageFormat.Bmp;
            }
            else if (cmbFileType.SelectedIndex == 2)
            {
                imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            }
            else
            {
                imgFormat = System.Drawing.Imaging.ImageFormat.Tiff;
            }

            // Save images
            try {
                for (int x = 0; x < segments.GetLength(0); x++)
                {
                    for (int y = 0; y < segments.GetLength(1); y++)
                    {
                        fileName = folderBrowserDialog.SelectedPath + "\\" + x.ToString() + "-" + y.ToString() + "." + imgFormat.ToString();

                        segments[x, y].Save(fileName, imgFormat);
                    }
                }
            }
            catch (Exception exp) {
                StaticMethods.ShowErrorMessage(MESSAGE_SAVE_ERROR, exp);
                return;
            }

            StaticMethods.ShowMessage(segments.Length.ToString() + " قطعه تصویر ذخیره شدند.");
        }
Esempio n. 6
0
        private void picOutput_MouseMove(object sender, MouseEventArgs e)
        {
            Point p;

            p = ImageAnalyzerObject.GetOriginalPixelLocation(
                (int)(e.X / _zoomScale), (int)(e.Y / _zoomScale));

            // If mouse does not leave the current cell, we should do nothing.
            if (p.X == _mouseInfo.OriginalPixelLocation.X && p.Y == _mouseInfo.OriginalPixelLocation.Y)
            {
                return;
            }
            else
            {
                _mouseInfo.OriginalPixelLocation = p;
            }

            if (p.X == -1)
            {
                // Mouse is in border area of output image
                lblStatusLeft.Text = "";
            }
            else
            {
                if (ImageAnalyzerObject.HighlightRegions)
                {
                    ImageAnalyzer.Region previouslyHighlightedRegion = ImageAnalyzerObject.HighlightedRegion;
                    ImageAnalyzer.Region r = ImageAnalyzerObject.Pixels[p.X, p.Y].Region;

                    ImageAnalyzerObject.HighlightedRegion = r;

                    // Invalidate picOutput
                    picOutput.Invalidate(ImageAnalyzerObject.GetRegionBoundariesOnOutputImage(r.Boundaries, _zoomScale));
                    if (previouslyHighlightedRegion != null)
                    {
                        picOutput.Invalidate(ImageAnalyzerObject.GetRegionBoundariesOnOutputImage(previouslyHighlightedRegion.Boundaries, _zoomScale));
                    }
                }
                #region Update Left Status Bar
                _tmpStrBuilder.Remove(0, _tmpStrBuilder.Length);//_tmpStrBuilder.Clear();
                _tmpStrBuilder.Append("XY={");
                _tmpStrBuilder.Append(p.X + 1);
                _tmpStrBuilder.Append(", ");
                _tmpStrBuilder.Append(ImageAnalyzerObject.Input.Height - p.Y);

                _tmpStrBuilder.Append("}  RGBA={");
                _tmpStrBuilder.Append(ImageAnalyzerObject.Pixels[p.X, p.Y].Color.R);
                _tmpStrBuilder.Append(", ");
                _tmpStrBuilder.Append(ImageAnalyzerObject.Pixels[p.X, p.Y].Color.G);
                _tmpStrBuilder.Append(", ");
                _tmpStrBuilder.Append(ImageAnalyzerObject.Pixels[p.X, p.Y].Color.B);
                _tmpStrBuilder.Append(", ");
                _tmpStrBuilder.Append(ImageAnalyzerObject.Pixels[p.X, p.Y].Color.A);

                _tmpStrBuilder.Append("}  ColorID={");
                _mouseInfo.ColorID = ImageAnalyzerObject.UsedColors[ImageAnalyzerObject.Pixels[p.X, p.Y].Color.ToArgb()];
                _tmpStrBuilder.Append(_mouseInfo.ColorID);
                _tmpStrBuilder.Append("}");

                lblStatusLeft.Text = _tmpStrBuilder.ToString();
                #endregion
            }


            #region Pan Image
            if ((e.Button == System.Windows.Forms.MouseButtons.Left) && (_selectedTool == Tool.Pan))
            {
                int deltaX = _mouseInfo.PanStartLocation.X - e.X;
                int deltaY = _mouseInfo.PanStartLocation.Y - e.Y;

                tabOutputImage.AutoScrollPosition = new Point(
                    deltaX - tabOutputImage.AutoScrollPosition.X,
                    deltaY - tabOutputImage.AutoScrollPosition.Y);
            }
            #endregion
        }
Esempio n. 7
0
 private void lnkStopAnalyze_Click(object sender, EventArgs e)
 {
     ImageAnalyzerObject.StopAnalyze();
 }
Esempio n. 8
0
 private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     //System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;
     // Start analyzing input image (in a worker thread)
     ImageAnalyzerObject.Analyze();
 }