繁体   English   中英

如何在图像控件中显示图像的原始大小

[英]How to display image it's original size in Image control

在此处输入图片说明 我尝试将CS​​S高度设置为自动,但是图像无法显示,因此我必须设置固定高度。 我尝试了调整大小模式,但它也没有用。 我尝试添加“ img响应式”,但是它也没有用。

CSS

.imgFile {
 width: 100%;
 max-width: 100%;
 height: 100px;
 max-height:100%;
 margin-left: 7px;
 margin-right: 0px;
 margin-top: 5px;
 margin-bottom: 1px;
 background-repeat: no-repeat;
 background-color: white;
 background-size: 100%, 100%;
}

Asp.net

   System.Web.UI.WebControls.Image image = new 
    System.Web.UI.WebControls.Image();
        image.ID = file.Name + file.Oid;
        image.Attributes.Add("class", "imgFile");
        image.Attributes.Add("class", "img-responsive");
        image.Style.Add("background-image", "'LogoHeaderHandler.axd?f=" 
    + file.Oid + "&" + DateTime.Now.ToFileTime() + "'");

看来您有2个问题。

1)Attributes.Add根据当前代码清除imgFile类。 如果两者都需要,则必须将它们添加到一行,如下所示:

 image.Attributes.Add("class", "imgFile img-responsive");
 //image.Attributes.Add("class", "img-responsive");

2)您的CSS具有以下内容:背景大小:100%,100%; 需要删除它以保留图像的“原始”尺寸,否则它将拉伸图像。

剩下的代码似乎可以为我提供您正在寻找的结果(*允许您的处理程序按预期方式工作...我在测试中没有模拟此部分)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM