嗨我需要将非托管图像转换为托管位图图像,我需要在图片框上显示,但我似乎抛出一个异常,说“对象引用没有设置为对象的实例”。有没有人对此有所了解?我已经注释了引发异常的行。
for (int i = 0; i < characters.Length; i++)
{
area = characters[i].Area;
UnmanagedImage numer = characters[i].Image;
System.Drawing.Image plateImage = numer.ToManagedImage();//Exception
numberplate = new Bitmap(new Bitmap(plateImage));
pictureBox2.Image = numberplate;
pictureBox2.Refresh();
}
我在C#
中使用Aforge.net框架更新
for (int i = 0; i < characters.Length; i++)
{
area = characters[i].Area;
Bitmap numer = characters[i].Image.ToManagedImage();
//System.Drawing.Image plateImage = numer.ToManagedImage();
//numberplate = new Bitmap(new Bitmap(plateImage));
pictureBox2.Image = numberplate;
pictureBox2.Refresh();
}
答案 0 :(得分:3)
嘿伙计们,我在Aforge.Net论坛上找到了这个代码,它似乎有效。
BlobCounterBase bc = new BlobCounter();
bc.FilterBlobs = true;
bc.MinHeight = 5;
bc.MinWidth = 5;
bc.ProcessImage(numberplate);
Blob[] blobs = bc.GetObjectsInformation();
MessageBox.Show(bc.ObjectsCount.ToString());
for (int i = 0, n = blobs.Length; i < n; i++)
{
if (blobs.Length > 0)
{
bc.ExtractBlobsImage(numberplate, blobs[i], true);
Bitmap copy = blobs[i].Image.ToManagedImage();
pictureBox2.Image = numberplate;
pictureBox2.Refresh();
}
}
答案 1 :(得分:0)
Bitmap managedImage = numer.ToManagedImage( );