首页 新闻 会员 周边 捐助

ASP.NET怎么让图片适应图片控件大小

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-07-17 16:40

上传回会员图像,有一大一小。怎么让图片来适应图片控件大小

oSice的主页 oSice | 初学一级 | 园豆:58
提问于:2012-07-17 09:30
< >
分享
所有回答(2)
0

用JS 获取

强行改变 一个对象模型下面  图片的大小  图片的大小让JS自动获取

落幕残情 | 园豆:34 (初学一级) | 2012-07-17 10:36
1
public static void ResizeImage(string image, string Okey, string key, int width, int height, string newimagename)
    {
        System.Drawing.Image oImg = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image));
 
        System.Drawing.Image oThumbNail = new System.Drawing.Bitmap(width, height);//, System.Drawing.Imaging.PixelFormat.Format24bppRgb

        System.Drawing.Graphics oGraphic = System.Drawing.Graphics.FromImage(oThumbNail);
 
        oGraphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
 
        //set smoothing mode to high quality
        oGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        //set the interpolation mode
        oGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        //set the offset mode
        oGraphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
 
        System.Drawing.Rectangle oRectangle = new System.Drawing.Rectangle(0, 0, width, height);
 
        oGraphic.DrawImage(oImg, oRectangle);
 
        if (newimagename == "")
        {
            if (image.Substring(image.LastIndexOf(".")) != ".png")
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image), System.Drawing.Imaging.ImageFormat.Jpeg);
            else
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image), System.Drawing.Imaging.ImageFormat.Png);
        }
        else
        {
            if (newimagename.Substring(newimagename.LastIndexOf(".")) != ".png")
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + newimagename), System.Drawing.Imaging.ImageFormat.Jpeg);
            else
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + newimagename), System.Drawing.Imaging.ImageFormat.Png);
        }
        oImg.Dispose();
    }
悟行 | 园豆:12559 (专家六级) | 2012-07-17 11:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册