简体   繁体   English

不支持ImageSharp指定的方法

[英]ImageSharp Specified Method is not supported

Hi I am using ImageSharp version 1.0.0-alpha9-00175. 嗨,我正在使用ImageSharp 1.0.0-alpha9-00175版本。 When i use the 当我使用

.Save(output, ImageFormats.Jpeg); 

I get the following 我得到以下 不支持

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. 如果我注释掉.Save行,代码将毫无例外地运行,但显然不会保存。 I have looked on stackoverflow and the issues on Github but to no avail. 我已经看过stackoverflow和Github上的问题,但无济于事。

Can anyone see something i can't? 谁能看到我看不到的东西?

So after taking @Waescher advice i opened an issue on Github with ImageSharp turns out the answer was staring me in the face. 因此,在接受@Waescher的建议后,我在ImageSharp的Github上打开了一个问题,结果答案就在我的面前。 The error is thrown not by ImageSharp but by the underlying stream i was attempting to write to. 错误不是由ImageSharp引发的,而是由我尝试写入的基础流引发的。

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

I added a new MemoryStream and used that code works now. 我添加了一个新的MemoryStream并使用了现在的代码。

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 #LearningEveryDay

Since you are using an alpha version of ImageSharp it might no be tested through all code paths. 由于您使用的是ImageSharp的Alpha版本,因此可能无法通过所有代码路径进行测试。 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: 如果切换到GitHub上aspnet的HttpAbstractions存储库 ,则可以看到抛出异常的行:

ReferenceReadStream : Line 168 ReferenceReadStream:第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. 通过尝试其他Save()重载甚至获得另一个图像处理工具包,您也可能很幸运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM