[英]Getting error “Specified method is not supported.” on bitmap.save in c#. CaptchaMvc 5
出現類似“不支持指定方法”的錯誤。
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);
}
我陷入其中。 請幫助解決此錯誤。 如果您需要有關此問題的更多信息,請告訴我。
我的猜測是您已經在此流中編寫了。
試着做
response.Clear();
預先。
如果流中已經寫入了某些內容,則您將嘗試在流的末尾進行寫入。
而且您無法設置System.Web.HttpResponse.OutputStream
流的位置,因為它是不可搜索的
CaptchaMvc(Mvc 5)中遇到了問題,終於解決了。 如果將來有人遇到此問題,請嘗試以下解決方法:
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.