ASP.NET顯示漸變圖片實(shí)現(xiàn)方法
先給大家來(lái)個(gè)最終效果:

實(shí)現(xiàn)效果,首先準(zhǔn)備一張圖片,高度為25pixel,寬度為1至3pixel漸變的圖片。可以這里下載。
還要準(zhǔn)備數(shù)據(jù):
Dictionary<int, int> Datas
{
get
{
Dictionary<int, int> d = new Dictionary<int, 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 (KeyValuePair<int, 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圖片處理三類經(jīng)典問(wèn)題
- ASP.NET中圖片顯示方法實(shí)例
- asp.net實(shí)現(xiàn)圖片以二進(jìn)制流輸出的兩種方法
相關(guān)文章
ASP.NET網(wǎng)站第一次訪問(wèn)慢的解決方法
這篇文章主要為大家詳細(xì)介紹了IIS8上ASP.NET第一次訪問(wèn)慢的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
asp.net中c#自定義事件的實(shí)現(xiàn)方法詳解
這篇文章主要介紹了asp.net中c#自定義事件的實(shí)現(xiàn)方法,較為詳細(xì)的分析了自定義實(shí)現(xiàn)的各個(gè)步驟的具體實(shí)現(xiàn)思路與技巧,并給出了一個(gè)完整的實(shí)例總結(jié),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12
.Net Core項(xiàng)目中NLog整合Exceptionless實(shí)例
這篇文章主要介紹了.Net Core項(xiàng)目中NLog整合Exceptionless實(shí)例,NLog主要是收集程序中的日志,Exceptionless可以統(tǒng)一收集管理并展示出來(lái)程序的日志,兩者結(jié)合使用,相得益彰。感興趣的小伙伴可以參考這篇文章2021-09-09
ASP.NET Session的七點(diǎn)認(rèn)識(shí)小結(jié)
ASP.NET Session的使用當(dāng)中我們會(huì)遇到很多的問(wèn)題,那么這里我們來(lái)談下經(jīng)常出現(xiàn)的一些常用ASP.NET Session的理解2011-07-07
asp.net TreeView遞歸循環(huán)子節(jié)點(diǎn)生成樹(shù)形菜單實(shí)例
這篇文章主要介紹了asp.net TreeView遞歸循環(huán)子節(jié)點(diǎn)生成樹(shù)形菜單的方法,涉及asp.net遞歸算法及節(jié)點(diǎn)操作相關(guān)技巧,需要的朋友可以參考下2016-07-07
ASP.NET通過(guò)Remoting service上傳文件
ASP.NET通過(guò)Remoting service上傳文件...2006-09-09

