예제 #1
0
 public frmImageShow(byte[,] imageData, string caption = "")
 {
     InitializeComponent();
     Image = Processing.ByteToImage(imageData);
     this.BackgroundImage = Image;
     this.ClientSize      = Image.Size;
     this.Text            = caption;
     this.Show();
 }
예제 #2
0
        private void Draw()
        {
            int index = CorrectingPageIndex();

            if (index >= 0)
            {
                Image imageToDrawOn;
                if (CorrectedPages[index].CheckImage.ProcessedImage)
                {
                    imageToDrawOn = Processing.ByteToImage(CorrectedPages[index].CheckImage.ScannedImage);

                    using (Graphics g = Graphics.FromImage(imageToDrawOn))
                    {
                        if (CorrectedPages[index].CheckImage.ItemAltsCheckedState != null)
                        {
                            // Draw box where there might be a problem
                            var problemList = CorrectedPages[index].AnalyzeTooManyAndDoubts();
                            using (var b = new SolidBrush(Color.FromArgb(
                                                              Program.UserSettings.colorMark[0],
                                                              Program.UserSettings.colorMark[1],
                                                              Program.UserSettings.colorMark[2],
                                                              Program.UserSettings.colorMark[3])))
                            {
                                for (int i = 0; i < problemList.Count; i++)
                                {
                                    var str           = problemList[i].Split('_');
                                    var problemString = str[0];
                                    for (int s = 1; s < str.GetLength(0) - 1; s++)
                                    {
                                        problemString += "_" + str[s];
                                    }
                                    var set = Program.Test.ItemSetByName(problemString);
                                    if (set != null)
                                    {
                                        int item      = Convert.ToInt16(str[str.GetLength(0) - 1]);
                                        var r1        = CorrectedPages[index].CheckImage.ItemAltRectangle(set.ItemAltPointGrid(item, 0), 4);
                                        var r2        = CorrectedPages[index].CheckImage.ItemAltRectangle(set.ItemAltPointGrid(item, set.NumberOfAlternatives - 1), 4);
                                        var blockSize = CorrectedPages[index].CheckImage.AdjustedBlockSize();
                                        g.FillRectangle(b, new RectangleF(r1.Left, r1.Top, r2.Right - r1.Left, r2.Bottom - r1.Top));
                                    }
                                }
                            }

                            // Draw boxes around itemalts
                            using (Pen
                                   pGreen = new Pen(Color.FromArgb(
                                                        Program.UserSettings.colorSure[0],
                                                        Program.UserSettings.colorSure[1],
                                                        Program.UserSettings.colorSure[2],
                                                        Program.UserSettings.colorSure[3]), 2),
                                   pRed = new Pen(Color.FromArgb(
                                                      Program.UserSettings.colorDoubt[0],
                                                      Program.UserSettings.colorDoubt[1],
                                                      Program.UserSettings.colorDoubt[2],
                                                      Program.UserSettings.colorDoubt[3]), 2))
                            {
                                for (int j = 0; j < Program.Test.Paper.Blocks.Y; j++)
                                {
                                    for (int i = 0; i < Program.Test.Paper.Blocks.X; i++)
                                    {
                                        var rect = CorrectedPages[index].CheckImage.ItemAltRectangle(i, j);
                                        if (CorrectedPages[index].CheckImage.ItemAltsCheckedState[i, j] == ItemCheckedState.Checked) // Sure that it is checked
                                        {
                                            g.DrawRectangle(pGreen, rect.X, rect.Y, rect.Width, rect.Height);
                                        }
                                        else if (CorrectedPages[index].CheckImage.ItemAltsCheckedState[i, j] == ItemCheckedState.Doubt) // Not sure if checked or not
                                        {
                                            g.DrawRectangle(pRed, rect.X, rect.Y, rect.Width, rect.Height);
                                        }
                                    }
                                }
                            }
                        }

                        // Draw "cursor"
                        if (selectedPosition.X >= 0 && selectedPosition.Y >= 0)
                        {
                            if (CorrectedPages[index].CheckImage.ItemAltsCheckedState[selectedPosition.X, selectedPosition.Y] != ItemCheckedState.Unknown &&
                                CorrectedPages[index].CheckImage.ItemAltsCheckedState[selectedPosition.X, selectedPosition.Y] != ItemCheckedState.Unavailable)
                            {
                                var rect = CorrectedPages[index].CheckImage.ItemAltRectangle(selectedPosition, 3);
                                g.DrawRectangle(new Pen(Color.FromArgb(
                                                            Program.UserSettings.colorCursor[0],
                                                            Program.UserSettings.colorCursor[1],
                                                            Program.UserSettings.colorCursor[2],
                                                            Program.UserSettings.colorCursor[3]), 2), rect.X, rect.Y, rect.Width, rect.Height);
                            }
                        }
                    }
                }
                else
                {
                    // No calibrated image available
                    imageToDrawOn = Processing.ByteToImage(CorrectedPages[index].CheckImage.ScannedImage);
                }
                SetImage(imageToDrawOn);
            }
            else
            {
                pictureBox.Image = null;
                pictureBox.Size  = new Size(200, 200);
            }
        }