怎样把图片缩小上传到服务器
解决方案 »
- 高分请教关于winform中webBrowser实现多线程问题
- 关于C#面向对象建模的问题~
- 请教各位用C#编写的简单抓取网页的spider代码
- web窗体不使用File field控件能完成选择路径的功能吗?
- 怎样取得如:http://www.XXXX.com/xx.txt文件里的内容?
- 用C#做WINDOWS编程,多窗体时窗体刷新问题
- 能不能把一个DataSet转化成一个byte[],然后又把这个byte[]转化回这个DataSet
- 那个控件可以实时显示raw图片
- 时间控件Calendar的选择问题,谁会?
- 求排课系统的算法,百分酬谢,不够另加!
- windows服务定时执行问题【在线等】
- 急~~~Winform图片读取出来,修改出错了
http://topic.csdn.net/u/20090927/12/c84daad0-1310-4d10-bdf8-77baacf652be.html
FileInfo[] files = dir.GetFiles(); foreach (FileInfo f in files)
{
if (f.Name.ToLower() == "thumbs.db")
continue; try
{
string name = f.Name.Substring(0,f.Name.LastIndexOf("."));
string extension = f.Name.Substring(f.Name.LastIndexOf(".") + 1); System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/admin/news/") + f.Name);
float scale = 250.0f / Math.Max(img.Width, img.Height);
int width = Convert.ToInt32(img.Width * scale);
int height = Convert.ToInt32(img.Height * scale);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
System.Drawing.Image newImage = bmp.GetThumbnailImage(width, height, null, IntPtr.Zero);
newImage.Save(Server.MapPath("~/admin/news/thumbs/") + name + "." + extension,System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
Response.Write(ex.Message + "<br>");
}
}