主頁(yè) > 知識(shí)庫(kù) > ASP.NET顯示漸變圖片實(shí)現(xiàn)方法

ASP.NET顯示漸變圖片實(shí)現(xiàn)方法

熱門(mén)標(biāo)簽:硅谷的囚徒呼叫中心 地方門(mén)戶(hù)網(wǎng)站 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 集中運(yùn)營(yíng)管理辦法 百度競(jìng)價(jià)排名 服務(wù)器配置 網(wǎng)站排名優(yōu)化 阿里云

先給大家來(lái)個(gè)最終效果:

實(shí)現(xiàn)效果,首先準(zhǔn)備一張圖片,高度為25pixel,寬度為1至3pixel漸變的圖片。可以這里下載。

還要準(zhǔn)備數(shù)據(jù):

Dictionaryint, int> Datas 
 { 
 get 
 { 
 Dictionaryint, int> d = new Dictionaryint, int>(); 
 d.Add(1, 35); 
 d.Add(2, 45); 
 d.Add(3, 20); 
 return d; 
 } 
 } 

ok,數(shù)據(jù)準(zhǔn)備完了,在aspx里放三個(gè)Label控件,當(dāng)然你可以顯示在其它控件或是標(biāo)簽中,有一點(diǎn)要注意的是Width="300",它是漸變圖片在100%的寬度:

asp:Label ID="Label1" runat="server" style="margin: 3px;" Text="" Width="300" BorderWidth="1">/asp:Label>br /> 
 asp:Label ID="Label2" runat="server" style="margin: 3px;" Text="" Width="300" BorderWidth="1">/asp:Label>br /> 
 asp:Label ID="Label3" runat="server" style="margin: 3px;" Text="" Width="300" BorderWidth="1">/asp:Label>br /> 

把數(shù)據(jù)顯示于Label上:

protected void Page_Load(object sender, EventArgs e) 
 { 
 Data_Binding(); 
 } 
 
 private void Data_Binding() 
 { 
 int totals = 100; 
 foreach (KeyValuePairint, int> kvp in Datas) 
 { 
 double rate = kvp.Value / (double)totals; 
 
 double width = rate * 300; 
 switch (kvp.Key) 
 { 
 case 1: 
  this.Label1.Text = GradientImage(width, rate); 
  break; 
 case 2: 
  this.Label2.Text = GradientImage(width, rate); 
  break; 
 case 3: 
  this.Label3.Text = GradientImage(width, rate); 
  break; 
 } 
 } 
 } 
 
 private string GradientImage(double width, double rate) 
 { 
 return "IMG height='21' src='images/bar.gif' width='" + width + "' align='absMiddle'> " + rate.ToString("p"); 
 } 

以上就是ASP.NET實(shí)現(xiàn)漸變圖片的方法,希望對(duì)大家的學(xué)習(xí)有所幫助。

您可能感興趣的文章:
  • ASP.NET實(shí)現(xiàn)圖片以二進(jìn)制的形式存入數(shù)據(jù)庫(kù)
  • asp.net 將一個(gè)圖片以二進(jìn)制值的形式存入Xml文件中的實(shí)例代碼
  • asp.net(c#)實(shí)現(xiàn)從sqlserver存取二進(jìn)制圖片的代碼
  • asp.net基于Web Service實(shí)現(xiàn)遠(yuǎn)程上傳圖片的方法
  • ASP.NET實(shí)現(xiàn)上傳圖片并生成縮略圖的方法
  • ASP.NET圖片處理三類(lèi)經(jīng)典問(wèn)題
  • ASP.NET中圖片顯示方法實(shí)例
  • asp.net實(shí)現(xiàn)圖片以二進(jìn)制流輸出的兩種方法

標(biāo)簽:開(kāi)封 甘孜 梧州 廣西 隨州 西雙版納 烏蘭察布 威海

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET顯示漸變圖片實(shí)現(xiàn)方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266