Search code examples
c#asp.net-corerazor-pagesimageprocessor

Generic GDI+ Error on Saving/loading image from MemoryStream using ImageProcessor


I'm having Generic GDI+ Error on line imageFactory.Load(inStream). My project is ASP.NET Core Razor-Pages.

I tried to clone inStream to new stream (this helped me before when saving bitmaps), but to no success.

Anyone dealt with something similar before?

// using ImageProcessor;
// using ImageProcessor.Imaging.Formats;

byte[] photoBytes = System.IO.File.ReadAllBytes(@"C:\Users\User\Desktop\img\img.jpg");
            ISupportedImageFormat format = new JpegFormat();
            Size size = new Size(200,200);
            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    var asd = inStream;

                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        imageFactory.Load(inStream)
                            .Resize(size)
                            .Format(format)
                            .Save(@"C:\Users\User\Desktop\ImgAdjusted\");
                    }
                }
            }

Solution

  • As per @itminus answer - this library is not designed to work in .net core.