GDI 中发生一般错误,可能是 server.mappath 问题
我已经将问题范围缩小到了这段代码,我在其中调整上传图像的大小并保存它。这在我的本地计算机上运行良好,但是当我在服务器上运行该站点时,我收到来自“thumbnail.Save”调用的通用 GDI+ 错误。
if(fup_displayPicUpload.HasFile)
{
string imageDir = Server.MapPath("./images/");
if (!Directory.Exists(imageDir + username))
{
Directory.CreateDirectory(imageDir + username);
lbl_profileMessage.ForeColor = Color.Yellow;
lbl_profileMessage.Text = "Created User Folder";
}
String userFolder = imageDir + username + "/";
using (System.Drawing.Image originalPhoto = new Bitmap(new MemoryStream(fup_displayPicUpload.FileBytes)))
{
System.Drawing.Image thumbnail = originalPhoto.GetThumbnailImage(300, 300, Abort, IntPtr.Zero);
thumbnail.Save(userFolder + "displaypicture.jpg", ImageFormat.Jpeg);
}
displayPictureUrl = "/images/" + username + "/displaypicture.jpg";
}
I've narrowed down the issue I'm having to this block of code, where I am resizing an uploaded image and saving it. This works fine on my local machine, but when I run the site on the server, I get a generic GDI+ error that's coming from the "thumbnail.Save" call.
if(fup_displayPicUpload.HasFile)
{
string imageDir = Server.MapPath("./images/");
if (!Directory.Exists(imageDir + username))
{
Directory.CreateDirectory(imageDir + username);
lbl_profileMessage.ForeColor = Color.Yellow;
lbl_profileMessage.Text = "Created User Folder";
}
String userFolder = imageDir + username + "/";
using (System.Drawing.Image originalPhoto = new Bitmap(new MemoryStream(fup_displayPicUpload.FileBytes)))
{
System.Drawing.Image thumbnail = originalPhoto.GetThumbnailImage(300, 300, Abort, IntPtr.Zero);
thumbnail.Save(userFolder + "displaypicture.jpg", ImageFormat.Jpeg);
}
displayPictureUrl = "/images/" + username + "/displaypicture.jpg";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最常见的原因是您尝试保存图像的目录出现访问被拒绝错误。确保运行应用程序的用户具有对目标目录的写访问权限。
The most common cause of this is an access denied error to the directory that you are trying to save the image to. Make sure that the user that the application is running as has write access to the destination directory.