简体   繁体   中英

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

Issue was faced in CaptchaMvc(Mvc 5), finally it has been resolved. 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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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