简体   繁体   English

在c#中的bitmap.save上出现错误“不支持指定的方法。” 验证码5

[英]Getting error “Specified method is not supported.” on bitmap.save in c#. CaptchaMvc 5

在此处输入图片说明

Getting error like "Specified method is not supported". 出现类似“不支持指定方法”的错误。

Validate.ArgumentNotNull(response, "response");
Validate.ArgumentNotNull(drawingModel, "drawingModel");
using (Bitmap bitmap = CaptchaUtils.ImageGeneratorFactory(drawingModel).Generate(drawingModel))
{
   response.ContentType = "image/gif";
   bitmap.Save(response.OutputStream, ImageFormat.Gif);
}

I am stuck in that. 我陷入其中。 Please help to resolve this error. 请帮助解决此错误。 Let me know if you want more info regarding this issue. 如果您需要有关此问题的更多信息,请告诉我。

My guess would be that you have already written in this stream. 我的猜测是您已经在此流中编写了。

Try to do 试着做

response.Clear();

beforehand. 预先。

If something was already written in the stream, you will try to write at the end of the stream. 如果流中已经写入了某些内容,则您将尝试在流的末尾进行写入。

And you cannot set position for System.Web.HttpResponse.OutputStream stream, because it is not seekable 而且您无法设置System.Web.HttpResponse.OutputStream流的位置,因为它是不可搜索的

Issue was faced in CaptchaMvc(Mvc 5), finally it has been resolved. CaptchaMvc(Mvc 5)中遇到了问题,终于解决了。 For future if any one face this issue than below is the solution you can try it: 如果将来有人遇到此问题,请尝试以下解决方法:

using (Bitmap image = CaptchaUtils.ImageGeneratorFactory(drawingModel).Generate(drawingModel))
{
    using (MemoryStream ms = new MemoryStream())
    {
        bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        ms.WriteTo(response.OutputStream);
    }
}

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

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