简体   繁体   中英

How to convert an Unmanaged Image to a managed bitmap image?

Hi I need to convert an unmanaged image to a managed bitmap image which I need to display on a picturebox but I it seems to throw an exception saying "object reference not set to an instance of an object". Does anyone have an idea about it? I have commented the line which throws the exception.

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

I am using Aforge.net framework with C#

UPDATE

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

I found this code on the Aforge.Net forums and it seemed to work.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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