目前我有很多像素很大的JPG图像文件,我想做一个程序把他们全部缩小。比如以前是1024*768的图片文件
我想用C#写一个程序,通过这个程序把图片转换成800*600的请问牛人能够实现吗?你们有这样的控件吗?
小弟先谢过了

解决方案 »

  1.   

    以一代码很好用,我也是这样用的,给你参考下:<%
    //' String urlpath="vl_pic_decorate\\";    //'财产图片路径(商店等)
    //' String goodpath="vl_pic_goods\\";      //'商品图片路径
    //'imgurl="C:\\Inetpub\\wwwroot\\virtual_life\\vl_pic_decorate\\1\\";
    int i=0;
    int n=0;
    String imgurl="";
    int h=0;
    int w=0;
    for(n=1;n<=5;n++)
    {
     i=n;
     imgurl="vl_pic_decorate\\1\\";
     imgurl=imgurl+i.ToString()+".jgp";
     System.Drawing.Image oldimg = System.Drawing.Image.FromFile(Server.MapPath(imgurl));
     System.Drawing.Image newimg = oldimg.GetThumbnailImage( 60, 60 * oldimg.Height/oldimg.Width,null,new System.IntPtr(0));
     String new_imgpath="vl_pic_decorate\\01\\"+i.ToString()+".jpg";
     newimg.Save(Server.MapPath(new_imgpath),System.Drawing.Imaging.ImageFormat.Jpeg);
    }/*
    System.Drawing.Image oldimg = System.Drawing.Image.FromFile( Server.MapPath(imgurl));
    System.Drawing.Image newimg = oldimg.GetThumbnailImage( 60, 60 * oldimg.Height/oldimg.Width,null,new System.IntPtr(0));
    string new_imgpath = imgurl.Substring(imgurl.IndexOf("/")+1,imgurl.IndexOf(".")-imgurl.IndexOf("/")-1);
    newimg.Save( Server.MapPath( "images/" ) + new_imgpath+"th.jpg",System.Drawin
    *//*
     System.Drawing.Bitmap Img_tmp = new System.Drawing.Bitmap(imgurl);
     h=100;
     w=100*(Img_tmp.Width/Img_tmp.Height);
     Graphics graphics = Graphics.FromImage(Img_tmp);
     graphics.DrawImage(Img_tmp,0,0,h,w);
     String new_imgpath="vl_pic_decorate\\01\\"+i.ToString()+".jpg";
     Img_tmp.Save(Server.MapPath(new_imgpath),System.Drawing.Imaging.ImageFormat.Jpeg); //'imgurl="C:\\head.bmp";  //'imgurl+"1.jpg";
     System.Drawing.Image oldimg = System.Drawing.Image.FromFile(Img_tmp);//'Server.MapPath(imgurl));
     System.Drawing.Image newimg = oldimg.GetThumbnailImage( 100, 100 * oldimg.Height/oldimg.Width,null,new System.IntPtr(0));
      String new_imgpath="vl_pic_decorate\\01\\";
    //'string new_imgpath = imgurl.Substring(imgurl.IndexOf("/")+1,imgurl.IndexOf(".")-imgurl.IndexOf("/")-1);
     newimg.Save(Server.MapPath(new_imgpath) + i.ToString()+".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
    */%>
      

  2.   

    /*  */这间这段是针对不同扩展名的图片而设置的,如果你的图片文件类型全部一致就不用这么麻烦,好比全部为为.jpeg,且文件名以1.jpg 2.jpg......这样保存的话,只要修改循环变量的量的值及图片的路径就行了