locked
ArgumentNullException: Value cannot be null. Parameter name: encoder when saving an image! RRS feed

  • Question

  • User991566988 posted

    Hi

    I've implemented this code to save images at my core 2.1 mvc project:

    https://github.com/drsaifyousif/TestingCoreIdentity

    Saving images was done successfully but suddenly it returns this error:

    ArgumentNullException: Value cannot be null. Parameter name: encoder

    I searched about it and found there is a solution by specifying the type of the image: (ImageExtensions.cs)

            public static byte[] ToByteArray(this Image current)
            {
                using (var stream = new MemoryStream())
                {
                    //current.Save(stream, current.RawFormat); Not Working
                    current.Save(stream, ImageFormat.Jpeg); // Working but will convert the type to Jpeg.
                    return stream.ToArray();
                }
            }

    How to let the first one works (RawFormat) which take the format of the image please?

    Friday, July 10, 2020 9:43 AM

Answers