当前位置: 代码迷 >> ASP.NET >> GridView显示图片解决方案
  详细解决方案

GridView显示图片解决方案

热度:7649   发布时间:2013-02-25 00:00:00.0
GridView显示图片
GridView如何按缩放比例显示大图片。



------解决方案--------------------------------------------------------
图像的属性宽和高百分比设置
------解决方案--------------------------------------------------------
图片可以同比缩小阿,就看你想怎么实现了;
C# code
public static void ShowImage(string imageUrl, System.Web.UI.WebControls.Image image1, int width, int height)    {        string Url = imageUrl;        try        {            System.Drawing.Image image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(Url));            System.Drawing.Size size = new System.Drawing.Size(image.Width, image.Height);            int w = size.Width;            int h = size.Height;            if (w > h)            {                if (w > width)                {                    w = width;                    h = (w * size.Height) / size.Width;                }            }            else            {                if (h > height)                {                    h = height;                    w = (h * size.Width) / size.Height;                }            }            image1.Attributes.Add("style", "width:" + w + "px;height:" + h + "px;");            image1.ImageUrl = Url;        }        catch        {            image1.ImageUrl = Url;        }    }
------解决方案--------------------------------------------------------
先正常加载,然后cs里 用楼上的方法,循环缩放。可以吗
  相关解决方案