GDI+中发生一般性错误
我的上传图片的代码是#region//上传图片方法publicstringUploadImage(){if(File1.PostedFile.FileName.Trim(...
我的上传图片的代码是
#region //上传图片方法
public string UploadImage()
{
if (File1.PostedFile.FileName.Trim() != "")
{
///上传文件
string extension = Path.GetExtension(File1.PostedFile.FileName).ToUpper();
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss");
string path = System.Web.HttpContext.Current.Server.MapPath("~/") + "Manager/productimage/" + fileName + extension;
File1.PostedFile.SaveAs(path);
//加图片水印
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("~/") + "Manager/productimage/shuiyin.png");
Graphics g = Graphics.FromImage(image);
g.DrawImage(copyImage, new Rectangle((image.Width - copyImage.Width) / 2, (image.Height - copyImage.Height) / 2,
copyImage.Width, copyImage.Height),0,0,copyImage.Width,copyImage.Height, GraphicsUnit.Pixel);
g.Dispose();
//保存加水印过后的图片,删除原始图片
string newPath = "Manager/productimage/" + fileName + "_new" + extension;
image.Save(newPath);
image.Dispose();
if (File.Exists(path))
{
File.Delete(path);
}
return newPath;
}
else
{
return null;
}
}
#endregion
然后再本地测试正常,发布到服务器上测试就报 GDI+中发生一般性错误
我不知道我的代码哪里有问题
高手帮我解决下, 很急,解决了另加分 展开
#region //上传图片方法
public string UploadImage()
{
if (File1.PostedFile.FileName.Trim() != "")
{
///上传文件
string extension = Path.GetExtension(File1.PostedFile.FileName).ToUpper();
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss");
string path = System.Web.HttpContext.Current.Server.MapPath("~/") + "Manager/productimage/" + fileName + extension;
File1.PostedFile.SaveAs(path);
//加图片水印
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("~/") + "Manager/productimage/shuiyin.png");
Graphics g = Graphics.FromImage(image);
g.DrawImage(copyImage, new Rectangle((image.Width - copyImage.Width) / 2, (image.Height - copyImage.Height) / 2,
copyImage.Width, copyImage.Height),0,0,copyImage.Width,copyImage.Height, GraphicsUnit.Pixel);
g.Dispose();
//保存加水印过后的图片,删除原始图片
string newPath = "Manager/productimage/" + fileName + "_new" + extension;
image.Save(newPath);
image.Dispose();
if (File.Exists(path))
{
File.Delete(path);
}
return newPath;
}
else
{
return null;
}
}
#endregion
然后再本地测试正常,发布到服务器上测试就报 GDI+中发生一般性错误
我不知道我的代码哪里有问题
高手帮我解决下, 很急,解决了另加分 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询