Aforge.NET - 从StringBuilder

时间:2016-04-06 17:30:12

标签: c# image-processing blob aforge getpixel

我正在创建一个旨在检查多项选择测试的程序。我的应用程序是指将搜索与背景颜色(白色)不同颜色的像素的正方形。 Stringbuilder我曾经排队各个点(方角)的位置。

我的问题是:StringBuilder如何在下面的代码块中看到, 首先为变量myPoint.X分配一个值myPoint.X(用逗号分隔)到变量myPoint.Y?在stringbuilder中,我用分号分隔点?

其次:有了这些点,我可以绘制正方形,在其间我会搜索像素吗?

感谢您的帮助。

public void ImageProcessing(PictureBox pbox, Bitmap bitmap, TextBox tb1)
        {
            //var nbitmap = UnmanagedImage.FromManagedImage(bitmap);
            bitmap = (Bitmap)pbox.Image.Clone();
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width,
                bitmap.Height),
                ImageLockMode.ReadWrite, bitmap.PixelFormat);
            ColorFiltering colorFiltering = new ColorFiltering();

            colorFiltering.Red = new IntRange(0, 64);
            colorFiltering.Green = new IntRange(0, 64);
            colorFiltering.Blue = new IntRange(0, 64);
            colorFiltering.FillOutsideRange = false;
            colorFiltering.ApplyInPlace(bitmapData);

            IntPoint myPoint = new IntPoint();

            BlobCounter blobCounter = new BlobCounter();
            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight = 15;
            blobCounter.MinWidth = 15;

            blobCounter.ProcessImage(bitmapData);
            Blob[] blobs = blobCounter.GetObjectsInformation();
            bitmap.UnlockBits(bitmapData);

            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();


            Graphics g = Graphics.FromImage(bitmap);
            Pen redPen = new Pen(Color.Red, 3);
            Pen bluePen = new Pen(Color.Blue, 3);
            List<IntPoint> corners = new List<IntPoint>();


            StringBuilder sb = new StringBuilder();
            string stg = "";


            List<IntPoint> zbior = new List<IntPoint>();

            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                List<IntPoint> edgePoints =     blobCounter.GetBlobsEdgePoints(blobs[i]);

                if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
                {

                    PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners);

                    Pen pen = null;

                    if (subType == PolygonSubType.Square)
                    {

                        pen = (corners.Count == 4) ? redPen : bluePen;
                        foreach (var item in corners)
                        {
                            sb.Append(item).Append(";");

                        }

                    }


                    g.DrawPolygon(pen, ToPointsArray(corners));
                }

            }
tb1.Text = stg;

                redPen.Dispose();
                bluePen.Dispose();
                g.Dispose();
                Clipboard.SetDataObject(bitmap);
                pbox.Image = bitmap;
            }

        }

1 个答案:

答案 0 :(得分:0)

通过调用其上的ToString()方法从StringBuilder返回字符串,该方法将返回整个字符串。

我不确定你想要的第二个问题,请问详细说明一下?