asp.net怎么把远程图片存到本地,并且重新设置尺寸? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary> /// 生成缩略图 /// </summary> /// <param name="PicW">缩略图宽度</param> /// <param name="PicH">缩略图高度</param> /// <res>按比例缩小</res> /// <returns></returns> public bool ReducedImage(int PicW, int PicH, string tFullName, ref string Err) { if (string.IsNullOrEmpty(tFullName)) { tFullName = HttpContext.Current.Server.MapPath("~/") + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".jpg"; } Image oImage = ResourceImage; int oWidth = oImage.Width; //原图宽度 int oHeight = oImage.Height; //原图高度 int tWidth = PicW; //设置缩略图初始宽度 int tHeight = PicH; //设置缩略图初始高度 //按比例计算出缩略图的宽度和高度 if (oWidth >= oHeight) { tHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(tWidth) / Convert.ToDouble(oWidth))); } else { tWidth = (int)Math.Floor(Convert.ToDouble(oWidth) * (Convert.ToDouble(tHeight) / Convert.ToDouble(oHeight))); } //生成缩略原图 Bitmap tImage = new Bitmap(PicW, PicH); Graphics g = Graphics.FromImage(tImage); g.InterpolationMode = InterpolationMode.High; //设置高质量插值法 g.SmoothingMode = SmoothingMode.HighQuality;//设置高质量,低速度呈现平滑程度 g.Clear(Color.White); //清空画布 //绘制 g.DrawImage(oImage, new Rectangle((PicW - tWidth) / 2, (PicH - tHeight) / 2, tWidth, tHeight), new Rectangle(0, 0, oWidth, oHeight), GraphicsUnit.Pixel); ////绘制边框 //g.DrawRectangle(new Pen(Color.Gray, 1), 0, 0, PicW - 1, PicH - 1); try { //以JPG格式保存图片 tImage.Save(tFullName, ImageFormat.Jpeg); return true; } catch (Exception e) { Err = e.Message; return false; } finally { //释放资源 oImage.Dispose(); g.Dispose(); tImage.Dispose(); } } 如果是这样的话,必须先要webClient把页面抓下来,再通过正则表达式,把带图片的链接取出来,可能还需要用webClient的download的方法把图片下载到你本地的目录上。 submit问题,为啥不起作用 [求助] 为什么我这个触发器不能编译通过? 緊急求助 帮忙:SQL语句?在线等 请问策略提醒是怎么回事? 请问怎样查文件名是否重复,和怎样删除文件?? 求各位高手帮看看,我这几个方法写的是否有毛病,是否有不完善之处,请各位帮我优化一下,不胜感激!!! 大家帮我看看这段代码 如何把ASP.NET web应用程序 放到IIS中调试? 我设置了断点,可是程序在调试的时候不停阿 有没有Dundas.Chart比较详细的使用说明 奇怪问题总是被我遇到
/// 生成缩略图
/// </summary>
/// <param name="PicW">缩略图宽度</param>
/// <param name="PicH">缩略图高度</param>
/// <res>按比例缩小</res>
/// <returns></returns>
public bool ReducedImage(int PicW, int PicH, string tFullName, ref string Err)
{
if (string.IsNullOrEmpty(tFullName))
{
tFullName = HttpContext.Current.Server.MapPath("~/") + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".jpg";
} Image oImage = ResourceImage;
int oWidth = oImage.Width; //原图宽度
int oHeight = oImage.Height; //原图高度
int tWidth = PicW; //设置缩略图初始宽度
int tHeight = PicH; //设置缩略图初始高度 //按比例计算出缩略图的宽度和高度
if (oWidth >= oHeight)
{
tHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(tWidth) / Convert.ToDouble(oWidth)));
}
else
{
tWidth = (int)Math.Floor(Convert.ToDouble(oWidth) * (Convert.ToDouble(tHeight) / Convert.ToDouble(oHeight)));
} //生成缩略原图
Bitmap tImage = new Bitmap(PicW, PicH);
Graphics g = Graphics.FromImage(tImage);
g.InterpolationMode = InterpolationMode.High; //设置高质量插值法
g.SmoothingMode = SmoothingMode.HighQuality;//设置高质量,低速度呈现平滑程度
g.Clear(Color.White); //清空画布 //绘制
g.DrawImage(oImage, new Rectangle((PicW - tWidth) / 2, (PicH - tHeight) / 2, tWidth, tHeight), new Rectangle(0, 0, oWidth, oHeight), GraphicsUnit.Pixel); ////绘制边框
//g.DrawRectangle(new Pen(Color.Gray, 1), 0, 0, PicW - 1, PicH - 1);
try
{
//以JPG格式保存图片
tImage.Save(tFullName, ImageFormat.Jpeg); return true;
}
catch (Exception e)
{
Err = e.Message;
return false; }
finally
{
//释放资源
oImage.Dispose();
g.Dispose();
tImage.Dispose();
} }