Hi,
I am getting exception on server when saving chapcha image in forder
A generic error occurred in GDI+. But is is working fine in local server without any error.
Please help me.
my codes .
using (Bitmap bitmap = new Bitmap(106, 35))
{
string imgCaptchaToSave = string.Empty;
string captchaText = Guid.NewGuid().ToString().Substring(0, 6);
ViewState["Captcha"] = captchaText.ToString();
using (Graphics graphics = Graphics.FromImage(bitmap))
{
Font font = new Font("Verdana", 25, FontStyle.Regular, GraphicsUnit.Pixel);
graphics.DrawString(captchaText, font, new SolidBrush(Color.FromArgb(255, 0, 0)), 0, 0);
imgCaptchaToSave = captchaText + ".jpg"; //Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".jpg";
// bitmap.Save(Server.MapPath("~/Images/Captcha/") + imgCaptchaToSave, ImageFormat.Jpeg);
using (var m = new MemoryStream())
{
bitmap.Save(m, ImageFormat.Jpeg);
var img = System.Drawing.Image.FromStream(m);
img.Save(Server.MapPath("~/Images/Captcha/") + imgCaptchaToSave);
}
imgCaptcha.ImageUrl = "~/Images/Captcha/" + imgCaptchaToSave;
imgCaptcha.Visible = true;
txtCaptchaText.Text = string.Empty;
graphics.Flush();
graphics.Dispose();
GC.Collect();
}
}