当我用 c# 写的组件 上传一张图片的时候,我要在图片的底部加上 “上传者某某”
有谁知道怎么做吗?

解决方案 »

  1.   

    http://www.cnblogs.com/index/archive/2004/10/20/54498.aspx
      

  2.   

    先生成缩略图,然后生命一个grapics,再调用graphics的drawrectangle()(好像是这么写的)。
    就是在指定的图像上用另外一幅图片覆盖,当然也可以用pen 对象在上面写字。
      

  3.   

    已经做好了,但是能不能给图片加高14px  然后在这 14 px 上加文字呢?if ((Ext.ToLower()==".gif")||(Ext.ToLower()==".bmp")||(Ext.ToLower()==".png")||(Ext.ToLower()==".jpg"))
    {
    string path = Server.MapPath(".") + "/WebOnLineEdit/UserUpLoadFile/" + FileName;
    System.Drawing.Image image = System.Drawing.Image.FromFile(path);
    Graphics g = Graphics.FromImage(image);
    g.DrawImage(image,0, 0, image.Width, image.Height);
    Font f = new Font("Verdana", 14);
    Brush b = new SolidBrush(Color.Black);
    string addText = "图源: WWW.aaaa.net (aaaa)";
    g.DrawString(addText, f, b, image.Width-270, image.Height-15);
    g.Dispose(); string newPath = Server.MapPath(".") + "/WebOnLineEdit/UserUpLoadFile/aaaaaa" + FileName ;
    image.Save(newPath); Response.Write(newPath);
    image.Dispose();
    if(File.Exists(path))
    {
    File.Delete(path);
    }
    FileName="aaaaaa"+FileName+"";
    }
      

  4.   

    为什么不能给 gif的图片加水印啊?
      

  5.   

    int fileLength = myFile1.PostedFile.ContentLength;
    if(fileLength>102400)
    {
    Response.Write("<script>alert(\"图片上传不能大于100K!\");history.back(-1);</script>");
    }
    //int index = 0;
    string delimeter1 = ".";
    int i = name.LastIndexOf("\\");
    string AttFileName = name.Substring(i);
    string[] aryfile;
    aryfile = AttFileName.Split(delimeter1.ToCharArray());
    string AttExtension = "jpg";
    // if(aryfile.Length>0)
      //  AttExtension = aryfile[aryfile.Length-1].ToString();
    Guid guid1 = Guid.NewGuid();
    filename = guid1.ToString();
    string filepath = MapPath(System.Configuration.ConfigurationSettings.AppSettings["datadir"].ToString());
    filepath += "Biz\\" + Request.Cookies["CurrentMemberID"].Value + "\\"; 
    System.IO.Directory.CreateDirectory(filepath);
    filename = filename+"."+AttExtension;
    filepath += filename;
    /*
     * 加入文字水印
     * */
    System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(myFile1.PostedFile.InputStream,true);
    int phWidth = imgPhoto.Width; 
    int phHeight =imgPhoto.Height;
    Bitmap image = new Bitmap(phWidth, phHeight,PixelFormat.Format24bppRgb);
    image.SetResolution(imgPhoto.HorizontalResolution,imgPhoto.VerticalResolution);
    Graphics g = Graphics.FromImage(image);
    g.SmoothingMode = SmoothingMode.AntiAlias;
    g.DrawImage(
    imgPhoto,                               
    new Rectangle(0, 0, phWidth, phHeight), 
    0,                                      
    0,                                       
    phWidth,                                
    phHeight,                               
    GraphicsUnit.Pixel); if(Request.Form["chkMark"]!=null)
    {
    int[] sizes = new int[]{64,48,32,16,8,6,4};//用指定Sizes绘制图片时,测量用指定的字串宽度
    Font crFont = null; 
    SizeF crSize = new SizeF(); 
    for (int j=0 ;j<7; j++)

    crFont = new Font("Arial", sizes[j],FontStyle.Bold);
    crSize = g.MeasureString(cm.CompanyName,crFont);
    if((ushort)crSize.Width < (ushort)phWidth)
    break;
    }
    Brush b = new SolidBrush(Color.White);
    string addText ="水印文字" ;
    g.DrawString(addText, crFont, b,10,(image.Height/2));
    }
    Font crFont2 = new Font("Arial", 10,FontStyle.Bold);
    SolidBrush b2 = new SolidBrush(Color.Orange);
    g.DrawString("sina.com", crFont2, b2, (phWidth-70),(phHeight-20));
    image.Save(filepath,ImageFormat.Jpeg);
    g.Dispose();
    image.Dispose();
    imgPhoto.Dispose();
      

  6.   

    发出去有点乱了,你自己整理一下吧。
    我这个是可以对gif生成水印的。
      

  7.   

    http://blog.csdn.net/greennetboy/archive/2005/12/17/554465.aspx
      

  8.   

    对,就是用Graphics类在图片上DrawString就可以了。找些GDI+相关资料就能完成了。
      

  9.   

    用缩略图水印组件wsImage3.5 
    www.wave12.com
      

  10.   

    可以参考一下 http://www.cinenn.com/blog/PermaLink,guid,004bff1f-2c76-4e49-8fe6-4fa96799571a.aspx