如何将非托管映像转换为托管位图映像



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

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

我正在使用 Aforge.net 框架与 C#

更新

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

我在 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();
                        }
                    }
Bitmap managedImage = numer.ToManagedImage( );

最新更新