如何遍历文件夹里的图片,,然后给这些图片打水印呢
遍历文件夹里的图片,是用什么方法
谢谢了

解决方案 »

  1.   

    system.io判断文件扩展名然后打开图片,在上面画图
      

  2.   

    缩略图水印组件wsImage3.5 批量加就可以
      

  3.   

    string extension = Path.GetExtension(File1.PostedFile.FileName).ToUpper(); 
    string fileName = DateTime.Now.ToString("yyyyMMddhhmmss"); string path = Server.MapPath(".") + "/upload/" + fileName + extension; 
    File1.PostedFile.SaveAs(path); 
    System.Drawing.Image image = System.Drawing.Image.FromFile(path);
    System.Drawing.Image copyImage = System.Drawing.Image.FromFile( Server.MapPath(".") + "/logo.gif"); 
    //Create a new FrameDimension object from this imageFrameDimension ImgFrmDim = new FrameDimension( image.FrameDimensionsList[0] );int nFrameCount = image.GetFrameCount( ImgFrmDim );// Save every frame into jpeg format for( int i = 0; i < nFrameCount; i++ )
    {
    image.SelectActiveFrame( ImgFrmDim, i );image.Save( string.Format( Server.MapPath(".") + "/upload/Frame{0}.jpg", i ), ImageFormat.Jpeg );
    }
    image.Dispose();for( int i = 0; i < nFrameCount; i++ )
    {
    string pa = Server.MapPath(".") + "/upload/Frame"+i+".jpg";
    System.Drawing.Image Image = System.Drawing.Image.FromFile(pa);
    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(); string newPath = Server.MapPath(".") + "/upload/" + fileName + "_new"+i.ToString()+ extension;
    Image.Save(newPath);Image.Dispose();if(File.Exists(pa))

    File.Delete(pa);
    } }
    if(File.Exists(path)) 

    File.Delete(path); 
    }
      

  4.   

    .net 可以直接弄。。不用组件。
      

  5.   

    下面是遍历文件夹的代码 private void Page_Load(object sender, System.EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("login.aspx");
            }
            DelFile();
            // 在此处放置用户代码以初始化页面
            string strdirlist = Request.QueryString.Get("dir");
            string FileList,ImgFilePath,SysPath;
            SysPath = "文件夹的虚拟路径";
            if (strdirlist == null) 
            {
                strdirlist = Server.MapPath(Application["UpLoadFilePath"].ToString());
            }
            ImgFilePath = strdirlist.Replace(SysPath, "../");
            DirectoryInfo directory = null;
            try
            {
                directory = new DirectoryInfo(strdirlist);
                //读取目录属性
                FileList = ("<p>Creation:" + directory.CreationTime.ToString() + "</p>");
                if (!(strdirlist == null || strdirlist == Server.MapPath(Application["UpLoadFilePath"].ToString())))
                {
                    FileList = FileList + "<ul><li><a href=\"javascript:history.go(-1);\">...</a></li></ul>";
                }
                
                DirectoryInfo[] subDirectory = directory.GetDirectories();
                FileList = FileList + "<ul>\n";
                for (int i = 0; i < subDirectory.Length; i++)
                {
                    FileList = FileList + "<li>";
                    FileList = FileList + "<a href=\"FileList.aspx?dir=" + strdirlist + "&IsFile=false \">×</a>&nbsp;";
                    FileList = FileList + "<a href=\"FileList.aspx?dir=" + Server.UrlEncode(subDirectory[i].FullName) + "\">" + subDirectory[i].Name;
                    FileList = FileList + "</a></li>\n";
                }
                FileList = FileList + "</ul>\n";
                FileInfo[] theFiles = directory.GetFiles();//可以使用GetFiles("*.txt")进行文件搜索
                FileList = FileList + "<ul>\n";
                for (int i = 0; i < theFiles.Length; i++)
                {
                    FileList = FileList + "<li>";
                    FileList = FileList + "<a href=\"#\"onclick=\"javascript:if  (confirm('你确定删除吗?'))  href='FileList.aspx?dir=" + strdirlist + "&IsFile=ok&DelFile=" + ImgFilePath + "/" + theFiles[i].Name + " ';else  return; \">×</a>&nbsp;";
                    FileList = FileList + " <a href=\" " + ImgFilePath + "/" + theFiles[i].Name + " \" target=\"_blank\">" + theFiles[i].Name + "</a>&nbsp;&nbsp;&nbsp;&nbsp;<span style='color: #999999'>" + theFiles[i].Length.ToString() + "&nbsp;Byte&nbsp;&nbsp;&nbsp;&nbsp;" + theFiles[i].LastWriteTimeUtc.ToString() + "</span></li>\n";
                    
                }
                FileList = FileList + "</ul>\n";
                FileDir.Text = FileList;
            }
            catch (Exception ex)
            {
                Response.Write("Access not possible. error:<i>");
                Response.Write(e.ToString() + "</i>");
                Response.End();
            }
        }
        private void DelFile() 
        {
            string DelImgUrl = Request.QueryString["DelFile"];
            DelImgUrl = Server.MapPath(DelImgUrl);
            if (Request.QueryString["IsFile"] == "ok") 
            {
                if (File.Exists(DelImgUrl))
                {
                    File.Delete(DelImgUrl);
                }
                Response.Write(Request.QueryString["DelFile"]);
            }
            if (Request.QueryString["IsFile"] == "false")
            {
                Response.Write(Request.QueryString["dir"]);
            }
        
        }
      

  6.   

    /**//// <summary>
                /// 添加图片水印
                /// </summary>
                /// <param name="oldpath">原图片绝对地址</param>
                /// <param name="newpath">新图片放置的绝对地址</param>
            private void addWaterMark(string oldpath,string newpath)
            
            {
                try
                {                System.Drawing.Image image = System.Drawing.Image.FromFile(oldpath);                Bitmap b = new Bitmap(image.Width, image.Height,PixelFormat.Format24bppRgb);
                    Graphics g = Graphics.FromImage(b);
                    g.Clear(Color.White);
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.InterpolationMode = InterpolationMode.High;
                
                    g.DrawImage(image, 0, 0, image.Width, image.Height);                if(如果需要填加水印)
                    {
                        switch(水印类型)
                        {
        //是图片的话               
                                       case "WM_IMAGE":
                                this.addWaterImage( g,Page.Server.MapPath(Waterimgpath),WaterPosition,image.Width,image.Height);
                                break;
        //如果是文字                    
                                       case "WM_TEXT":
                                this.addWaterText( g, WaterText,WaterPosition
                                    ,image.Width,image.Height);
                                break;
                        }                    b.Save(newpath);
                        b.Dispose();
                        image.Dispose();
                    }            }
                catch
                {
                
                    if(File.Exists(oldpath))
                    {
                        File.Delete(oldpath);
                    }
                }
                finally
                {
                    
                    if(File.Exists(oldpath))
                    {
                        File.Delete(oldpath);
                    }
                
                
                }
            
                    
            }
      

  7.   

    前期写了一个代码网站水印工具 。http://download.csdn.net/source/161135
    估计能符合你的要求