Exemplo n.º 1
0
        public void SetZone(IOcrPage ocrPage, int zoneIndex, bool isVisible, bool isNameVisible)
        {
            _ocrPage   = ocrPage;
            _zoneIndex = zoneIndex;

            IsVisible         = isVisible;
            mylabel.IsVisible = isNameVisible;

            if (_ocrPage != null && _zoneIndex >= 0 && _zoneIndex < _ocrPage.Zones.Count)
            {
                OcrZone zone = _ocrPage.Zones[_zoneIndex];
                if (string.IsNullOrEmpty(zone.Name))
                {
                    mylabel.Text = "Zone " + (_zoneIndex + 1).ToString();
                }
                else
                {
                    mylabel.Text = zone.Name;
                }

                if (zone.ZoneType == OcrZoneType.None || zone.ZoneType == OcrZoneType.Graphic || zone.ZoneType == OcrZoneType.Barcode)
                {
                    RasterColor color = RasterColorConverter.FromColor(Color.FromArgb(32, Color.Yellow));
                    this.Fill   = AnnSolidColorBrush.Create(color.ToString());//Color.FromArgb(32, Color.Yellow)
                    this.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), new LeadLengthD(1));
                }
                else
                {
                    this.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Red"), new LeadLengthD(1));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 縦、又は横を走査して指定色が所定のカウント数分連続していたらエラーとする
        /// </summary>
        /// <param name="strFile"></param>
        /// <returns></returns>
        private bool CheckCorrupt(string strFile)
        {
            int iPointX = (int)this.numPointX.Value;
            int iPointY = (int)this.numPointY.Value;

            using (var tempImage = codecs.Load(strFile))
            {
                int iCorruptCount = 0;                        // 対象色の連続カウント
                int iLimitCount   = (int)this.numPixel.Value; // 連続カウントの限界値
                // ターゲットカラー(System.Drawing.ColorをLeadtools.RasterColorに変換)
                RasterColor targetColor = RasterColorConverter.FromColor(cpTargetColor.Color);
                if (this.cmbDirection.SelectedIndex == 0)
                {
                    // 縦方向に走査
                    int iHeight = tempImage.Height;
                    for (int i = 0; i < iHeight; i++)
                    {
                        //RasterColor sourceColor = tempImage.GetPixel(i, 0);
                        if (RasterColor.Equals(targetColor, tempImage.GetPixel(i, iPointX)) == true)
                        {
                            iCorruptCount += 1;
                        }
                        else
                        {
                            iCorruptCount = 0;
                        }
                        if (iCorruptCount == iLimitCount)
                        {
                            // 限界値に達したらエラーとする
                            return(false);
                        }
                    }
                }
                else
                {
                    // 横方向に走査
                    int iWidth = tempImage.Width;
                    for (int i = 0; i < iWidth; i++)
                    {
                        //RasterColor sourceColor = tempImage.GetPixel(0, i);
                        if (RasterColor.Equals(targetColor, tempImage.GetPixel(iPointY, i)) == true)
                        {
                            iCorruptCount += 1;
                        }
                        else
                        {
                            iCorruptCount = 0;
                        }
                        if (iCorruptCount == iLimitCount)
                        {
                            // 限界値に達したらエラーとする
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
 public static RasterColor FromGdiPlusColor(Color color)
 {
     return(RasterColorConverter.FromColor(color));
 }
Exemplo n.º 4
0
 public static Color ToGdiPlusColor(RasterColor color)
 {
     return(RasterColorConverter.ToColor(color));
 }
Exemplo n.º 5
0
        private void ShowMousePositionAndImageColor(RasterImage image, LeadPoint viewerPoint, LeadPoint imagePoint)
        {
            // This point is now in image coordinates, i.e., 0,0 is the top-left area of the image
            // Since we passed 'false' to 'accountForViewPerspective' above, the point is what we see
            // if the data in the image is top-left (point 0, 0, is the most left-top point in the image data)
            // This is called the ViewPerspective of the image. Not all images supported by LEADTOOLS have top-left coordinates,
            // for example, when you load a BMP file, by the default, the image data is "flipped" and has a view perspective of
            // bottom-left. We could pass 'true' for images like that if we need to convert the point to the
            // actual pixel x, y in the image. We will do that later in the code below

            string imagePointText;
            bool   outside = false;

            // Check if the viewer point is outside the image coordinates
            if (imagePoint.X < 0 || imagePoint.Y < 0 || imagePoint.X > image.ImageWidth || imagePoint.Y > image.ImageHeight)
            {
                outside = true;
            }

            if (outside)
            {
                // Outside
                imagePointText = "OUTSIDE";
            }
            else
            {
                imagePointText = string.Format("{0}, {1}", imagePoint.X, imagePoint.Y);
            }

            // Show both points
            _mousePositionLabel.Text = string.Format(
                "Viewer: {0}, {1} - Image: {2}",
                viewerPoint.X, viewerPoint.Y,
                imagePointText);

            // Get the color under the cursor

            RasterColor pointCursorColor;

            // Use the imagePoint, we will use Raster.GetPixel. This method except the points
            // to be in image coordinates and in the image view perspective.
            // Since we had the point in top-left (by not passing true to accountForViewPerspective),
            // we must convert it to image coordinate first using RasterImage.PointToImage
            if (!outside)
            {
                LeadPoint colorPoint = new LeadPoint(imagePoint.X, imagePoint.Y);
                colorPoint = image.PointToImage(RasterViewPerspective.TopLeft, colorPoint);

                // GetPixel takes row/column, or Y and X
                pointCursorColor = image.GetPixel(colorPoint.Y, colorPoint.X);
            }
            else
            {
                // Either outside the image or we do not have an image
                pointCursorColor = RasterColor.FromKnownColor(RasterKnownColor.Transparent);
            }

            _cursorColorValueLabel.Text = pointCursorColor.ToString();
            _colorCursorPanel.BackColor = RasterColorConverter.ToColor(pointCursorColor);

            // Finally, if we are not drawing an interactive user rectangle and the cursor is over the
            // overlay rect, change its shape to a Hand

            if (!rubberBandMode.IsEnabled)
            {
                if (!_overlayRect.IsEmpty && _overlayRect.Contains(imagePoint.X, imagePoint.Y))
                {
                    _imageViewer.Cursor = Cursors.Hand;
                }
                else
                {
                    _imageViewer.Cursor = Cursors.Default;
                }
            }
        }