<asp:FileUpload ID="FileUpload1" runat="server" Width="428px" />用的是VS2005//图片文件上传部分
            if (FileUpload1.FileName == null || FileUpload1.FileName == string.Empty)
            {
                Response.Write("上传的图片数据丢失或者大于1MK..无法上传.限制1M以内!<br>");
                Response.End();
            }
            else
            {
                string name = FileUpload1.FileName;
                int size = FileUpload1.PostedFile.ContentLength;
                string type = FileUpload1.PostedFile.ContentType;
                string type2 = name.Substring(name.LastIndexOf(".") + 1);
                string protimename = System.DateTime.Now.ToString("yyyyMMddHHmmssms");
                FileName = protimename + "." + type2;
                string waterpic = "txt_" + protimename + "." + type2; //水印图片名称                string path = Server.MapPath("/upload/propic") + "\\" + FileName;
                string txt_path = Server.MapPath("/upload/txt_propic") + "\\" + waterpic; //水印图片保存地址                if (type != "image/pjpeg" && type != "image/gif" && type2 != "jpg" && type2 != "gif")
                {
                    Response.Write("上传的文件格式不正确,仅支持JPG或GIF格式的图片!<br>");
                    Response.End();
                }
                if (size <= 0 || size > 1200000)
                {
                    Response.Write("上传的图片数据丢失或者大于500K..无法上传.限制500K以内!<br>");
                    Response.End();
                }
                FileUpload1.SaveAs(path);
                AddWater(waterpic, txt_path);
            }/**/
    /// <summary>
    /// 在图片上增加文字水印
    /// </summary>
    /// <param name="sPath">原服务器图片路径</param>
    /// <param name="Path_sy">生成的带文字水印的图片路径</param>
    protected void AddWater(string sPath, string Path_sy)
    {
        string addText = "51aspx.com";
        System.Drawing.Image image = System.Drawing.Image.FromFile(sPath);
        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
        g.DrawImage(image, 0, 0, image.Width, image.Height);
        System.Drawing.Font f = new System.Drawing.Font("Verdana", 60);
        System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Green);        g.DrawString(addText, f, b, 35, 35);
        g.Dispose();        image.Save(Path_sy);
        image.Dispose();
    }为什么老是提示
txt_200812301649164916.jpg 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IO.FileNotFoundException: txt_200812301649164916.jpg源错误: 
行 129:    {
行 130:        string addText = "51aspx.com";
行 131:        System.Drawing.Image image = System.Drawing.Image.FromFile(sPath);
行 132:        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
行 133:        g.DrawImage(image, 0, 0, image.Width, image.Height);
 

解决方案 »

  1.   

    错误定位在:行 131:        System.Drawing.Image image = System.Drawing.Image.FromFile(sPath);请求帮助!!!
      

  2.   


    ..........
    string waterpic = "txt_" + protimename + "." + type2; //水印图片名称......
    string txt_path = Server.MapPath("/upload/txt_propic") + "\\" + waterpic; //水印图片保存地址
    .......AddWater(waterpic, txt_path);
      

  3.   

    System.Drawing.Image image = System.Drawing.Image.FromFile(sPath);这个时候明显 找不到文件啊,你再仔细看看你的代码,或者你调试下,
      

  4.   


    string waterpic = "txt_" + protimename + "." + type2; //水印图片名称AddWater(waterpic, txt_path);System.Drawing.Image image = System.Drawing.Image.FromFile(sPath);System.Drawing.Image image = System.Drawing.Image.FromFile(sPath);
    spath是图片的地址
    而楼主传的是图片名称!!!
      

  5.   

    我这里有个例子 参考下吧本地图片的图片水印实现 using System.Drawing;using System.Drawing.Imaging;using System.IO; public void ImageMark()    {        //添加水印后的图片的暂存路径        string newPath = MapPath(@"~//Images/BookCovers/") + filename + "_new" + ".jpg";        //需要水印的图片路径        string Path = Server.MapPath(".") + "/Images/BookCovers/" + filename + ".jpg";        System.Drawing.Image image = System.Drawing.Image.FromFile(Path);        //获得水印图片        System.Drawing.Image copyimage = System.Drawing.Image.FromFile(Server.MapPath(".") + "/Images/WaterMark.jpg");        Graphics g = Graphics.FromImage(image);        g.DrawImage(copyimage, new Rectangle(image.Width - copyimage.Width, image.Height - copyimage.Height, copyimage.Width, copyimage.Height), 0, 0, copyimage.Width, copyimage.Height, GraphicsUnit.Pixel);        g.Dispose();        image.Save(newPath, ImageFormat.Jpeg);        image.Dispose();        //删除原图           File.Delete(Path);             //得到新图        System.Drawing.Image NewImage = System.Drawing.Image.FromFile(newPath);        //保存新图至原位置          NewImage.Save(Path, ImageFormat.Jpeg);        NewImage.Dispose();        //删除暂存图        File.Delete(newPath);    } 
    注1:filename为图片文件名,文件名的获得方法自行选择.
    注2:保存图片需用绝对路径.