Beispiel #1
0
        public StartEndPoint[] GetLetters(int[,] clearPoints)
        {
            Dictionary<int, StartEndPoint> points = new Dictionary<int, StartEndPoint>();

            for (int x = 0; x < storeXMax; x++)
            {
                for (int y = 0; y < storeYMax; y++)
                {
                    int label = clearPoints[x, y];
                    if (label == 0) continue;

                    StartEndPoint pt;
                    if (!points.ContainsKey(label))
                    {
                        pt = new StartEndPoint { StartX = x, StartY = y, EndX = x, EndY = y};
                        points.Add(label, pt);
                        continue;
                    }

                    pt = points[label];

                    if (x < pt.StartX) pt.StartX = x; if (x > pt.EndX) pt.EndX = x;
                    if (y < pt.StartY) pt.StartY = y; if (y > pt.EndY) pt.EndY = y;
                }
            }

            if (points.Count == 0) return null;

            int i = 0;
            StartEndPoint[] fPoints = new StartEndPoint[points.Count];
            foreach (StartEndPoint se in points.Values) fPoints[i++] = se;

            return fPoints.ToArray();
        }
Beispiel #2
0
        public Bitmap Clip(StartEndPoint se)
        {
            Rectangle cropRect = new Rectangle(se.StartPoint.X, se.StartPoint.Y,
                se.EndPoint.X - se.StartPoint.X + 1, se.EndPoint.Y - se.StartPoint.Y + 1);
            Bitmap target = new Bitmap(cropRect.Width, cropRect.Height);

            using(Graphics g = Graphics.FromImage(target))
            {
                g.DrawImage(bmp, new Rectangle(0, 0, target.Width, target.Height),
                    cropRect,
                    GraphicsUnit.Pixel);
            }

            return target;
        }
Beispiel #3
0
        public void DrawRectangle(StartEndPoint se, Color color)
        {
            Rectangle drawRect = new Rectangle(se.StartPoint.X, se.StartPoint.Y,
                se.EndPoint.X - se.StartPoint.X + 1, se.EndPoint.Y - se.StartPoint.Y + 1);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawRectangle(new Pen(color), drawRect);
            }
        }