简体   繁体   English

Aforge.NET - 从StringBuilder获取项目

[英]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). Stringbuilder我曾经排队各个点(方角)的位置。

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? 我的问题是:你可以在下面的代码块中看到的StringBuilder如何首先为变量myPoint.X分配一个值(用逗号分隔)到变量myPoint.Y? In stringbuilder I separate the points by a semicolon? 在stringbuilder中,我用分号分隔点数?

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. 通过调用其上的ToString()方法从StringBuilder返回字符串,该方法将返回整个字符串。

I'm not sure want your second question is though, could you please elaborate? 我不确定你想要的第二个问题,请问详细说明一下?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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