这么说罢,上传一张图片,800X600,1M,在缩略图中要显示80X60,100K。  请问在asp.net 中如何实现,请高人们说个方法,有源码最好..

解决方案 »

  1.   

    请自行google之,哪个解决办法有问题,再来提问
    http://www.google.com/search?rlz=1C1GGLS_enCN291CN303&sourceid=chrome&ie=UTF-8&q=asp.net+缩略图
      

  2.   

    O(∩_∩)O~,LS的LS说的一点都没错,不管遇到什么问题,先自行解决,不管是google还是baidu,实在搞不定,再问。
      

  3.   

    asp.net缩略图代码
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Drawing.Drawing2D;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls; 
    namespace SQLWEB
    {
     /// <summary>
     /// SmallImage 的摘要说明。
     /// 这是介绍图像的缩略图的生成方法,代码已经写好,调试成功
     /// </summary>
     public class SmallImage : System.Web.UI.Page
     {
      private void Page_Load(object sender, System.EventArgs e)
      {
       // 在此处放置用户代码以初始化页面
       this.SendSmallImage(@"D:\pictrue\爱的四季\200579163536427.jpg",@"D:\pictrue\爱的四季\200579163536427Copy.jpg",150,150);
      }
      
      private static Size NewSize(int maxWidth,int maxHeight,int Width,int Height)
      {
       double w=0.0;
       double h=0.0;
       double sw=Convert.ToDouble(Width);
       double sh=Convert.ToDouble(Height);
       double mw=Convert.ToDouble(maxWidth);
       double mh=Convert.ToDouble(maxHeight);
     
       if(sw<mw && sh<mh)//如果maxWidth和maxHeight大于源图像,则缩略图的长和高不变
       {
        w=sw;
        h=sh;
       }
       else if((sw/sh)>(mw/mh))
       {
        w=maxWidth;
        h=(w*sh)/sw;
       }
       else
       {
        h=maxHeight;
        w=(h*sw)/sh;
       }
       return new Size(Convert.ToInt32(w),Convert.ToInt32(h));
      } 
      public  void SendSmallImage(string filename,string newfile ,int maxHeight,int maxWidth)
      {
       System.Drawing.Image img=System.Drawing.Image.FromFile(filename);//源图像的信息
       System.Drawing.Imaging.ImageFormat thisformat=img.RawFormat; //源图像的格式 
       Size newSize=NewSize(maxWidth,maxHeight,img.Width,img.Height); //返回调整后的图像Width与Height
       Bitmap outBmp=new Bitmap(newSize.Width,newSize.Height);
       Graphics g=Graphics.FromImage(outBmp);
       //设置画布的描绘质量
       g.CompositingQuality =CompositingQuality.HighQuality;
       g.SmoothingMode=SmoothingMode.HighQuality;
       g.InterpolationMode=InterpolationMode.HighQualityBicubic;
       g.DrawImage(img,new Rectangle(0,0,newSize.Width,newSize.Height),0,0,img.Width,img.Height,GraphicsUnit.Pixel);
       g.Dispose();
       //以下代码为保存图片时,设置压缩质量
       EncoderParameters encoderParams=new EncoderParameters();
       long[] quality=new long[1];
       quality[0]=100;
       EncoderParameter encoderParam= new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,quality);
       encoderParams.Param[0]=encoderParam;
       //获取包含有关内置图像编码解码器的信息的ImageCodecInfo对象。
       ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
       ImageCodecInfo jpegICI=null;
       for(int x=0;x<arrayICI.Length;x++)
       {
        if(arrayICI[x].FormatDescription.Equals("JPEG"))
        {
         jpegICI=arrayICI[x];//设置jpeg编码
         break;
        }
       }
       if(jpegICI!=null)
       {
        outBmp.Save(newfile,jpegICI,encoderParams);
       }
       else 
       {
        outBmp.Save(newfile,thisformat);
       }
       img.Dispose();
       outBmp.Dispose();
      } 
      #region Web 窗体设计器生成的代码
      override protected void OnInit(EventArgs e)
      {
       //
       // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
       //
       InitializeComponent();
       base.OnInit(e);
      }
      
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {    
       this.Load += new System.EventHandler(this.Page_Load); 
      }
      #endregion
     }
    }