0

嗨,我需要将非托管图像转换为需要在图片框上显示的托管位图图像,但我似乎抛出了一个异常,说“对象引用未设置为对象的实例”。有人对此有想法吗?我已经评论了引发异常的行。

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();                            
                    }
4

2 回答 2

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();
                        }
                    }
于 2012-08-09T15:51:58.227 回答
0
Bitmap managedImage = numer.ToManagedImage( );
于 2012-08-09T08:37:18.150 回答