AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

UnsupportedImageFormatException

The forum is to discuss topics related to different areas of image processing and computer vision.

UnsupportedImageFormatException

Postby FirstLast » Thu Mar 02, 2017 12:51 pm

I am trying to find lines in an image, but no matter what I do I always get an UnsupportedImageFormatException.

The original format of the image is 32bpp but even after converting it to 24bpp I still get the exception.
I tried every solution to this exception I found online but nothing changes.

So far I converted my 32bit image to 24 bit trying one of two methods :
Code: Select all
var copy = AForge.Imaging.Image.Clone(bitmapImage, PixelFormat.Format24bppRgb);

OR
Code: Select all
var copy = bitmapImage.ConvertToFormat(PixelFormat.Format24bppRgb);

Code: Select all
public static Bitmap ConvertToFormat(this Image image, PixelFormat format)
        {
            Bitmap copy = new Bitmap(image.Width, image.Height, format);
            using (Graphics gr = Graphics.FromImage(copy))
            {
                gr.DrawImage(image, new Rectangle(0, 0, copy.Width, copy.Height));
            }
            return copy;
        }


I also tried other overloads of the ProcessImage but it did not help:

Code: Select all
var copy = AForge.Imaging.Image.Clone(bitmapImage, PixelFormat.Format24bppRgb);
            int stride = copy.Width / 8 + 1;
            IntPtr imgData = copy.GetHbitmap(Color.Empty);

            AForge.Imaging.UnmanagedImage ui = new AForge.Imaging.UnmanagedImage(imgData, copy.Width, copy.Height, stride, copy.PixelFormat);
            hl.ProcessImage(ui);



Code: Select all
AForge.Imaging.HoughLineTransformation hl = new AForge.Imaging.HoughLineTransformation();

            var copy = AForge.Imaging.Image.Clone(bitmapImage, PixelFormat.Format24bppRgb);
            int stride = copy.Width / 8 + 1;
            IntPtr imgData = copy.GetHbitmap(Color.Empty);

            BitmapData bmpd = new BitmapData();
            bmpd.Scan0 = imgData;
            bmpd.Stride = stride;
            bmpd.Width = copy.Width;
            bmpd.Height = copy.Height;
            bmpd.PixelFormat = copy.PixelFormat;
            hl.ProcessImage(bmpd);


ALL of these cause an UnsupportedImageFormatException. I don't understand this, supposedly the ProcessImage method can work with a 24bpp image but apparently it is not the case, because neither of the conversions prevents the exception.
Why is this happening?
How can I actually get this to work?
FirstLast
 
Posts: 1
Joined: Thu Mar 02, 2017 12:22 pm

Re: UnsupportedImageFormatException

Postby andrew.kirillov » Thu Mar 02, 2017 2:21 pm

The exception makes perfect sense and tells exactly what is the problem - the image processing routine you are using does not support pixel format of the image you are giving to it.

FirstLast wrote:I tried every solution to this exception I found online but nothing changes.

You missed one thing though - reading documentation of the HoughLineTransformation class. It clearly tells your image must be 8bpp grayscale image. So do grayscaling first.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to Image Processing and Computer Vision