簡體   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