0

I have problem in converting System.Drawing.Image to Emgu.CV.Image. i can load my image in formapplication

string im_name = str[index];
Emgu.CV.Image<Bgr, Byte> img = new Image<Bgr, byte>(im_name);

but this code gives me error of invalid arguments

System.Drawing.Image img_btmap = System.Drawing.Image.FromFile( im_name);

Emgu.CV.Image<Bgr, Byte> img1 = new Image<Bgr, byte>(img_btmap);

Somebody has idea why??? regards

Andrei Pana
  • 4,484
  • 1
  • 26
  • 27
Shahgee
  • 3,303
  • 8
  • 49
  • 81

1 Answers1

2

Change the line to:

System.Drawing.Bitmap img_btmap = new System.Drawing.Bitmap(im_name);

The Emgu.CV.Image constructor is expecting Bitmap class which inherits from Image class.

Make sure to dispose img_btmap later otherwise you risk the file being locked.

Edit: most simple way of ensuring proper disposing is using the using block like this:

using (System.Drawing.Bitmap img_btmap = new System.Drawing.Bitmap(im_name))
{
   //.....rest of code comes here.....
}
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • Yup, or just the Image(string) constructor. – Hans Passant Jan 02 '11 at 15:26
  • u are right , i have finished it already with [System.Drawing.Bitmap img_btmap = new System.Drawing.Bitmap(im_name);]and it works but i was expecting other explaination because messagaebox shows already image as bitmap. thanx but what about disposing and dangerof file lock – Shahgee Jan 02 '11 at 16:21
  • @sayyad Bitmap is Image but Image is not Bitmap that's why it didn't work before, regarding disposing see my edit - the "danger" is having the image file locked (e.g. you can't delete it) until garbage collection takes place. – Shadow The GPT Wizard Jan 02 '11 at 21:59