Beispiel #1
0
            /// <summary>
            /// 刪除取樣點
            /// </summary>
            /// <param name="removePickIndex">移除取樣點索引</param>
            public void RemovePick(int removePickIndex)
            {
                if (removePickIndex >= _PickInfos.Count || removePickIndex < 0)
                {
                    return;
                }

                Pick removePick = _PickInfos[removePickIndex];

                _PickInfos.Remove(removePick);
                CurrentPickIndex = -1;

                int      cot    = ConvertImage.PixelCount;
                BitArray useMap = new BitArray(cot);

                foreach (Pick pick in _PickInfos)
                {
                    useMap.Or(pick.UseMap);
                }

                IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly);

                unsafe
                {
                    byte *convertP = (byte *)convertPtr.ToPointer();
                    for (int i = 0; i < cot; i++)
                    {
                        if (removePick.UseMap[i] && !useMap[i])
                        {
                            byte v = (byte)((convertP[0] + convertP[1] + convertP[2]) / 3);
                            convertP[0] = v;
                            convertP[1] = v;
                            convertP[2] = v;
                        }
                        convertP += 4;
                    }
                }
                ConvertImage.UnlockBits();
            }
Beispiel #2
0
        private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
        {
            if (_ScaleImage != null)
            {
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                if (_HoverColor == Color.Empty)
                {
                    e.Graphics.DrawString("點選圖片選擇取樣顏色", _InfoFont, Brushes.Blue, _InfoRect, _InfoFormat2);
                }
                else
                {
                    using (SolidBrush brush = new SolidBrush(_HoverColor))
                    {
                        Rectangle rectEll = new Rectangle(_InfoRect.Left + 2, _InfoRect.Top + (_InfoRect.Height - _ColorPotWidth) / 2, _ColorPotWidth, _ColorPotWidth);

                        e.Graphics.FillEllipse(Brushes.Gray, rectEll);
                        rectEll.Offset(-2, -2);
                        e.Graphics.FillEllipse(brush, rectEll);

                        string info = null;
                        string tip  = null;
                        if (_MouseDown)
                        {
                            Pick pick = _Converter.GetPick(_Converter.CurrentPickIndex);
                            info = string.Format("色差容許值:{0}\n檢測範圍:{1}", pick.Allowance, pick.Range);
                            tip  = "滑鼠上下:調整容許值\n左右:調整範圍";
                        }
                        else if (_HoverIndex >= 0)
                        {
                            Pick pick = _Converter.GetPick(_HoverIndex);
                            info = string.Format("色差容許值:{0}\n檢測範圍:{1}", pick.Allowance, pick.Range);
                            tip  = "左鍵:調整容許值與範圍\n右鍵:刪除採樣點";
                        }
                        else
                        {
                            tip = "左鍵:新增採樣點";
                        }

                        int left   = _InfoRect.Left + _ColorPotWidth + 8;
                        int top    = _InfoRect.Top;
                        int width  = _InfoRect.Width - _ColorPotWidth - 5;
                        int height = _InfoRect.Height;
                        if (info == null)
                        {
                            Rectangle rectInfo = new Rectangle(left, top, width, height);
                            e.Graphics.DrawString(tip, _InfoFont, Brushes.Maroon, rectInfo, _InfoFormat2);
                        }
                        else
                        {
                            //Font font = pane new Font(_InfoFont.FontFamily, 12);
                            if (width < 300)
                            {
                                int       width1    = (int)(width * 0.65F);
                                Font      font      = new Font(_InfoFont.FontFamily, width / 30);
                                Rectangle rectInfo1 = new Rectangle(left, top, width / 2, height);
                                Rectangle rectInfo2 = new Rectangle(left + width / 2, top, width / 2, height);
                                e.Graphics.DrawString(info, font, Brushes.RoyalBlue, rectInfo1, _InfoFormat2);
                                e.Graphics.DrawString(tip, font, Brushes.Maroon, rectInfo2, _InfoFormat2);
                            }
                            else
                            {
                                Rectangle rectInfo1 = new Rectangle(left, top, 150, height);
                                Rectangle rectInfo2 = new Rectangle(left + 150, top, width - 150, height);
                                e.Graphics.DrawString(info, _InfoFont, Brushes.RoyalBlue, rectInfo1, _InfoFormat2);
                                e.Graphics.DrawString(tip, _InfoFont, Brushes.Maroon, rectInfo2, _InfoFormat2);
                            }
                        }
                    }
                }

                e.Graphics.DrawImage(_ScaleImage.Image, _ImageRect);
                foreach (Pick pick in _Converter.GetPickList())
                {
                    int       potX       = pick.DisplayPoint.X + _ImageRect.Left;
                    int       potY       = pick.DisplayPoint.Y + _ImageRect.Top;
                    Rectangle rectFull   = new Rectangle(potX - _AllowanceHalfWidth, potY - _AllowanceHalfWidth, _AllowanceHalfWidth * 2, _AllowanceHalfWidth * 2);
                    Rectangle rectCenter = new Rectangle(potX - _AllowanceCenterWidth, potY - _AllowanceCenterWidth, _AllowanceCenterWidth * 2, _AllowanceCenterWidth * 2);
                    using (SolidBrush fillBrush = new SolidBrush(Color.FromArgb(140, 255 - pick.Color.R, 255 - pick.Color.G, 255 - pick.Color.B)))
                        using (SolidBrush centerBrush = new SolidBrush(pick.Color))
                            using (Pen centerPen = new Pen(pick.Color, _AllowanceCenterWidth))
                            {
                                e.Graphics.FillEllipse(fillBrush, rectFull);
                                e.Graphics.FillEllipse(centerBrush, rectCenter);

                                int maxWid   = _AllowanceHalfWidth - _AllowanceCenterWidth;
                                int lineLenV = (int)(maxWid * ((float)pick.Allowance / Pick.MaxAllowance));
                                int lineLenH = (int)(maxWid * ((float)pick.Range / Pick.MaxRange));

                                if (lineLenV > 0)
                                {
                                    e.Graphics.DrawLine(centerPen, potX, potY + lineLenV + _AllowanceCenterWidth,
                                                        potX, potY - lineLenV - _AllowanceCenterWidth);
                                }

                                if (lineLenH > 0)
                                {
                                    e.Graphics.DrawLine(centerPen, potX + lineLenH + _AllowanceCenterWidth, potY,
                                                        potX - lineLenH - _AllowanceCenterWidth, potY);
                                }
                            }
                    e.Graphics.DrawEllipse(Pens.Black, rectFull);
                    e.Graphics.DrawEllipse(Pens.White, rectFull.Left + 1, rectFull.Top + 1, rectFull.Width - 2, rectFull.Height - 2);
                }
            }
            else
            {
                e.Graphics.DrawString("選擇開啟圖片或將檔案拖曳至此區域", _InfoFont, Brushes.Red, splitContainer1.Panel1.ClientRectangle, _InfoFormat);
            }
        }
Beispiel #3
0
        private void splitContainer1_Panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (_MouseDown)
            {
                int dX = e.X - _MouseDownPoint.X;
                int dY = e.Y - _MouseDownPoint.Y;
                Cursor.Position = new Point(Cursor.Position.X - dX, Cursor.Position.Y - dY);

                _Converter.CurrentValuePlus(-dY, dX * 10);
                splitContainer1.Panel1.Invalidate(_ImageRect);
                splitContainer1.Panel2.Invalidate(_ImageRect);
                splitContainer1.Update();
            }
            else
            {
                if (Function.InRectangle(e.Location, _ImageRect))
                {
                    int    pickIdx   = -1;
                    int    potX      = e.X - _ImageRect.Left;
                    int    potY      = e.Y - _ImageRect.Top;
                    double checkDist = Math.Pow(_AllowanceHalfWidth, 2); // 控制區域半徑平方
                    var    picks     = _Converter.GetPickList();
                    for (int i = 0; i < picks.Count; i++)
                    {
                        Pick pick = picks[i];
                        if (Math.Pow(pick.DisplayPoint.X - potX, 2) + Math.Pow(pick.DisplayPoint.Y - potY, 2) < checkDist)
                        {
                            pickIdx = i;
                            break;
                        }
                    }

                    bool refresh = _HoverIndex != pickIdx;
                    if (pickIdx < 0)
                    {
                        int x = (int)(potX / _Scale);
                        int y = (int)(potY / _Scale);
                        if (x >= _ScaleImage.Width)
                        {
                            x = _ScaleImage.Width - 1;
                        }
                        if (y >= _ScaleImage.Height)
                        {
                            y = _ScaleImage.Height - 1;
                        }
                        _HoverIndex = -1;
                        _HoverColor = _ScaleImage.GetPixel(x, y);
                        Cursor      = Cursors.Cross;
                    }
                    else
                    {
                        Cursor      = Cursors.Hand;
                        _HoverIndex = pickIdx;
                        _HoverColor = _Converter.GetPick(pickIdx).Color;
                    }

                    if (refresh)
                    {
                        splitContainer1.Panel2.Invalidate(_ImageRect);
                    }
                }
                else
                {
                    _HoverIndex = -1;
                    _HoverColor = Color.Empty;
                    Cursor      = Cursors.Default;
                }
            }
            splitContainer1.Panel1.Invalidate(_InfoRect);
        }