求救http 500内部服务器错误
本人写了个水印处理图片:
在本地debug时没有任何问题:
但是上传至服务器运行时就会报 http 500内部服务器错误
private void UploadImg(string newFileName)
{
//上传大图片
string txt = this.txtProcess.Text;
if (txt == "")
{
txt = "哈哈";
}
string path = Server.MapPath("~/goods/");
//对图片进行水印处理
makeWatermark(10, 10, txt, this.fileupImage.PostedFile.FileName, newFileName, path);
//生成缩略图并上传
string s = Server.MapPath("~/goods/" + newFileName);
string paths = Server.MapPath("~/goods/sGoods/");
SmallPic(s, paths + newFileName, 150, 200);
}
/// <summary>
/// 缩小图片
/// </summary>
/// <param name="strOldPic">源图文件名(包括路径)</param>
/// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
/// <param name="intWidth">缩小至宽度</param>
/// <param name="intHeight">缩小至高度</param>
public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)
{
System.Drawing.Bitmap objPic, objNewPic;
try
{
objPic = new System.Drawing.Bitmap(strOldPic);
int width = objPic.Width;
//按比例缩放
double proportion =(double)(125) / width;
int h=Convert.ToInt32( objPic.Height*proportion);
int w= Convert.ToInt32(objPic.Width*proportion);
// objNewPic = new System.Drawing.Bitmap(objPic,Convert.ToInt32(intWidth * proportion) ,Convert.ToInt32( intHeight * proportion));
objNewPic = new System.Drawing.Bitmap(objPic, w, h);
objNewPic.Save(strNewPic);
objPic.Dispose();
objNewPic.Dispose();
}
catch (Exception exp)
{
// this.ClientScript.RegisterStartupScript(this.GetType(), "msg", "alert('" + exp.Message + "!')", true);
throw exp;
}
finally
{
objPic = null;
objNewPic = null;
}
}
/// <summary>
/// 水印处理
/// </summary>
/// <param name="x">文字绘制在图片上的坐标x</param>
/// <param name="y">文字绘制在图片上的坐标x</param>
/// <param name="txt">水印文本</param>
/// <param name="fPath">要处理的图片本地路径</param>
/// <param name="name">保存时的文件名</param>
/// <param name="mPath">上传至服务器的路径</param>
public void makeWatermark(int x, int y, string txt, string fPath, string name, string mPath)
{
// System.Drawing.FontStyle fstyle=new System.Drawing.FontStyle();
try
{
System.Drawing.Image image = System.Drawing.Image.FromFile(fPath);
//实例化绘图对象
System.Drawing.Graphics e = System.Drawing.Graphics.FromImage(image);
//实例化font对象
System.Drawing.Font f = new System.Drawing.Font(System.Drawing.FontFamily.GenericMonospace, 24, System.Drawing.FontStyle.Bold);
//实例化brush
System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
e.DrawString(txt, f, b, image.Width / 15, image.Height / 10);
e.Dispose();
int width = image.Width;
double proportion = (double)(600) / width;
int h = Convert.ToInt32(image.Height * proportion);
int w = Convert.ToInt32(image.Width * proportion);
System.Drawing.Bitmap bt = new System.Drawing.Bitmap(image, w, h);
bt.Save(mPath + name, System.Drawing.Imaging.ImageFormat.Jpeg);
bt.Dispose();
}
catch (Exception exp)
{
// this.ClientScript.RegisterStartupScript(this.GetType(), "msg", "alert('" + exp.Message + "!')", true);
throw exp;
}
}