我正在尝试使用Aforge.Net框架处理图像。我想在二进制图像上计算圆度量。这是我的c#代码;
List<IntPoint> edgePoints; //Global variables
List<IntPoint> corners; //Global variables
Bitmap _imageInvert; //Global varibles
// Here is something code
// For instance, applying some filters and some processing
// pictureBox2 has a _imageInvert and running below lines
AForge.Imaging.Blob[] blobs = blobCounter.GetObjectsInformation();
double[] blobAdjustedSize = new double[blobs.Length];
for ( int i = 0, n = blobs.Length; i < n; i++ )
{
edgePoints = blobCounter.GetBlobsEdgePoints( blobs[i] );
corners = PointsCloud.FindQuadrilateralCorners( edgePoints );
}
Graphics grafik = Graphics.FromImage( _imageInvert ); //GIVING ERROR
Pen myPen = new Pen( System.Drawing.Color.Red, 15 );
DrawEdge( grafik, myPen, edgePoints );
private static System.Drawing.Point[] PointsListToArray( List<IntPoint> list )
{
System.Drawing.Point[] array = new System.Drawing.Point[list.Count];
for ( int i = 0, n = list.Count; i < n; i++ )
{
array[i] = new System.Drawing.Point( list[i].X, list[i].Y );
}
return array;
}
// Draw object's edge
private static void DrawEdge( Graphics g, Pen pen, List<IntPoint> edge )
{
System.Drawing.Point[] points = PointsListToArray( edge );
if ( points.Length > 1 )
{
g.DrawLines( pen, points );
}
else
{
g.DrawLine( pen, points[0], points[0] );
}
}
当我点击运行时,我收到错误。
错误: System.Drawing.dll中出现未处理的“System.Exception”类型异常
附加信息:无法从具有索引像素格式的图像创建Graphics对象。
如何在_BoxI2上绘制egdepoints,以便在pictureBox2上绘制。提前致谢。 (对不起我的语言。)
类似的屏幕截图是here。