怎么样用C#缩小图片文件

menghun1355 2005-08-29 11:08:54
目前我有很多像素很大的JPG图像文件,我想做一个程序把他们全部缩小。

比如以前是1024*768的图片文件
我想用C#写一个程序,通过这个程序把图片转换成800*600的

请问牛人能够实现吗?你们有这样的控件吗?
小弟先谢过了

...全文
590 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
clbo 2005-08-29
  • 打赏
  • 举报
回复
楼上的代码不错!!
不放弃我追求 2005-08-29
  • 打赏
  • 举报
回复
/* */这间这段是针对不同扩展名的图片而设置的,如果你的图片文件类型全部一致就不用这么麻烦,好比全部为为.jpeg,且文件名以1.jpg 2.jpg......这样保存的话,只要修改循环变量的量的值及图片的路径就行了
不放弃我追求 2005-08-29
  • 打赏
  • 举报
回复
以一代码很好用,我也是这样用的,给你参考下:

<%
//' 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);
*/

%>
menghun1355 2005-08-29
  • 打赏
  • 举报
回复
呵呵再加一句
转换后保存在硬盘上!

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧