日期:2014-05-17  浏览次数:20950 次

asp.net 根据图片地址URL 生成缩略图片
急!!!
通过一个图片的url 生成一张图片

------解决方案--------------------
几种方式:
1、读取图片,然后用C#的方法重新生成一张新的图片,再用新的图片显示,我原来就是这么做的。
2、使用脚本,没用过,你可以查查
------解决方案--------------------
引用:
急!!!
通过一个图片的url 生成一张图片
http://download.csdn.net/detail/ce2010/4465793
------解决方案--------------------
public void MakeThumbnail(string imgPath_old, int width, int height)
{
  
  System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(System.IO.File.ReadAllBytes(imgPath_old)));
 
  int towidth = width; int toheight = height;
  int x = 0; int y = 0; int ow = img.Width;
  int oh = img.Height;
  // 按值较大的进行等比缩放(不变形) 
  if ((double)img.Width / (double)towidth < (double)img.Height / (double)toheight)
  {
    toheight = height;
    towidth = img.Width * height / img.Height;
  }
  else
  {
    towidth = width;
    toheight = img.Height * width / img.Width;
  }
  //新建一个bmp图片
  System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
  //新建一个画板
  System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
  //设置高质量插值法
  g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
  //设置高质量,低速度呈现平滑程度
  g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  //清空画布并以透明背景色填充
  g.Clear(System.Drawing.Color.Transparent);
  //在指定位置并且按指定大小绘制原图片的指定部分
  g.DrawImage(img, new System.Drawing.Rectangle(0, 0, towidth, toheight),
  new System.Drawing.Rectangle(x, y, ow, oh),