简体   繁体   中英

Aforge.NET - Get items from StringBuilder

I'm creating a program that is designed to check multiple choice tests. My application is meant squares which will search the pixels of a different color than the background color (white). Stringbuilder I used to line up the position of individual points (square corners).

My question is: How the StringBuilder, which you can see in the codeblock below, first assign a value to a variable myPoint.X a second (separated by commas) to the variable myPoint.Y? In stringbuilder I separate the points by a semicolon?

Secondly: Is having these points I can draw squares, between which I will search the pixels?

Thanks for help.

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;
            }

        }

You return the string from a StringBuilder by calling the ToString() method on it, which will return the entire string.

I'm not sure want your second question is though, could you please elaborate?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM