如题

解决方案 »

  1.   

      /// <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();
                }        }
      

  2.   

    如果是这样的话,必须先要webClient把页面抓下来,再通过正则表达式,把带图片的链接取出来,可能还需要用webClient的download的方法把图片下载到你本地的目录上。