1

Hi I am using ImageSharp version 1.0.0-alpha9-00175. When i use the

.Save(output, ImageFormats.Jpeg); 

I get the following Not SupportedException

Here is my code

   input.Seek(0, SeekOrigin.Begin);
        using (Image<Rgba32> image = Image.Load<Rgba32>(input))
        {

            if (image.Width >= image.Height)    //landscape
            {
                ratio = image.Height / defaultWidth;                  
            }
            else //portrait
            {
                ratio = image.Width / defaultHeight;                   
            }

            image.Resize(image.Width / ratio, image.Height / ratio)
               .Crop(defaultWidth, defaultHeight)                   
                .Save(output, ImageFormats.Jpeg);
        }

If i comment out the .Save line the code runs without exception but obviously wont save. I have looked on stackoverflow and the issues on Github but to no avail.

Can anyone see something i can't?

James South
  • 10,147
  • 4
  • 59
  • 115
MOSCODE
  • 272
  • 7
  • 16

2 Answers2

2

So after taking @Waescher advice i opened an issue on Github with ImageSharp turns out the answer was staring me in the face. The error is thrown not by ImageSharp but by the underlying stream i was attempting to write to.

Microsoft.AspNetCore.Http.Internal.ReferenceReadStream.Write(byte[] buffer, int offset, int count)

I added a new MemoryStream and used that code works now.

MemoryStream outputs = new MemoryStream(); 

image.Resize(image.Width / ratio, image.Height / ratio)
           .Crop(defaultWidth, defaultHeight)                   
            .Save(outputs, ImageFormats.Jpeg);

Thanks for the help guys. #LearningEveryDay

MOSCODE
  • 272
  • 7
  • 16
1

Since you are using an alpha version of ImageSharp it might no be tested through all code paths. If you look at the call stack you see this line:

Microsoft.AspNetCore.Http.Internal.ReferenceReadStream.Write(byte[] buffer, int offset, int count)

If you switch over to the aspnet's HttpAbstractions repository on GitHub, you can see the line the exception is thrown:

ReferenceReadStream : Line 168

    public override void Write(byte[] buffer, int offset, int count)
    {
        throw new NotSupportedException();
    }

So there's not much you can do right now except getting involved in these projects as well. At least you could open an issue in the given repository. You might also be lucky by trying other Save() overloads or even getting another image processing toolkit.

Waescher
  • 5,361
  • 3
  • 34
  • 51
  • 4
    There's nothing wrong with the library, It's a read stream so can't be written to. No way we can really test for this and shouldn't be either. – James South Aug 22 '17 at 14:27