0

I am trying this example but I got "Source pixel format is not supported by the filter" error, and to solve it I tried with these answeres but I got titled error, then I tried to solve it with these answers. But I am out of luck and I keep getting this error.

Can anyone give me a solution?

Heres the code:

        // Open your image
        string path = "sample2.jpg"; //taken from first example links initial image.
        Bitmap image = (Bitmap)Bitmap.FromFile(path);

        // The original bitmap with the wrong pixel format. 
        // You can check the pixel format with originalBmp.PixelFormat
        //Bitmap originalBmp = new (Bitmap)Image.FromFile("YourFileName.gif");

        // Create a blank bitmap with the same dimensions
        Bitmap tempBitmap = new Bitmap(image.Width, image.Height);

        // From this bitmap, the graphics can be obtained, because it has the right PixelFormat
        using (Graphics g = Graphics.FromImage(tempBitmap))
        {
            // Draw the original bitmap onto the graphics of the new bitmap
            g.DrawImage(image, 0, 0);
            // Use g to do whatever you like
            //g.DrawLine(...);
        }

        //Bitmap EditableImg = new Bitmap(image);

        Bitmap a = AForge.Imaging.Image.Clone(tempBitmap, PixelFormat.Format8bppIndexed); //currently getting titled error here.
        AForge.Imaging.Image.SetGrayscalePalette(a);

        // create filter
        DifferenceEdgeDetector filter = new DifferenceEdgeDetector();
        // apply the filter
        filter.ApplyInPlace(image);

error image for reference: enter image description here

Rifat
  • 1,700
  • 3
  • 20
  • 51
  • Does this answer your question? [Graphics on indexed image](https://stackoverflow.com/questions/17313285/graphics-on-indexed-image) – Ash Burlaczenko Jun 20 '20 at 00:03
  • It does not, see its accepted ans not working on picture. I knew someone will suggest this despite it is linked on question, so I attached the picture. Please check. – Rifat Jun 20 '20 at 02:35
  • You make it as 32 bit bitmap, and somehow want to clone it into an 8-bit bitmap? How do you expect that to work? Are you aware of what an 8-bit image actually is? If you want to change it to grayscale, there are much better methods for that that don't involve changing it to a pixel format that no .Net classes can manipulate as image. – Nyerguds Sep 10 '20 at 13:01

0 Answers0