| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7880 人关注过本帖
标题:ASP.NET动态生成进度条图片
取消只看楼主 加入收藏
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
结帖率:100%
收藏
 问题点数:0 回复次数:7 
ASP.NET动态生成进度条图片

效果图片:

图片附件: 游客没有浏览图片的权限,请 登录注册


//Jack.Lee 2007-10-28
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

/// <summary>
/// this class for build Some pictures for web-ui
/// </summary>
public class UIMaps
{
public UIMaps()
{
}

/// <summary>
/// Build a progress width this value in UIProgressProperty structure
/// </summary>
/// <param name="uiprspty">Property</param>
/// <returns>a bitmap</returns>
public Bitmap BuildDefault(UIProgressProperty uiprspty)
{
if (uiprspty.Width <= 5 || uiprspty.Height <= 3)
return null;
#region Init
//Measure Value
int rValueWidth = 0;
if (uiprspty.Value <= 0)
{
rValueWidth = 0;
uiprspty.Value = 0;
}
else if (uiprspty.Value > uiprspty.maxValue)
{
rValueWidth = uiprspty.Width;
uiprspty.Value = uiprspty.maxValue;
}
else
rValueWidth = (int)((float)((float)uiprspty.Value / (float)uiprspty.maxValue) * uiprspty.Width); //real length of data
//Caption
uiprspty.Text += Convert.ToString((int)(((float)uiprspty.Value / (float)uiprspty.maxValue) * 100)) + "%"; //%20

Bitmap map = new Bitmap(uiprspty.Width, uiprspty.Height);
Graphics g = Graphics.FromImage(map);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;

//background
g.FillRectangle(new SolidBrush(uiprspty.backColor),
new Rectangle(0, 0, uiprspty.Width, uiprspty.Height));
#endregion

#region datas
//datas
//g.FillRectangle(new SolidBrush(uiprspty.fColor1),
// new Rectangle(0, 1, rValueWidth, uiprspty.Height - 2));

Rectangle topleftrc = new Rectangle(1, 1, rValueWidth / 2, uiprspty.Height / 2);
if (topleftrc.Width <= 0) topleftrc.Width = 1;
LinearGradientBrush topleft = new LinearGradientBrush(topleftrc,
uiprspty.fColor1, uiprspty.fColor2,
LinearGradientMode.ForwardDiagonal);

Rectangle toprgtrc = new Rectangle((rValueWidth / 2) + 1, 1, rValueWidth / 2, uiprspty.Height / 2);
if (toprgtrc.Width <= 0) toprgtrc.Width = 1;
LinearGradientBrush toprgt = new LinearGradientBrush(toprgtrc,
uiprspty.fColor1, uiprspty.fColor2,
LinearGradientMode.BackwardDiagonal);

Rectangle btmleftrc = new Rectangle(1, (uiprspty.Height / 2) - 1, rValueWidth / 2, uiprspty.Height / 2);
if (btmleftrc.Width <= 0) btmleftrc.Width = 1;
LinearGradientBrush btmleft = new LinearGradientBrush(btmleftrc,
uiprspty.fColor2, uiprspty.fColor1, LinearGradientMode.BackwardDiagonal);

Rectangle btmrgtrc = new Rectangle((rValueWidth / 2) + 1, (uiprspty.Height / 2) - 1, rValueWidth / 2, uiprspty.Height / 2);
if (btmrgtrc.Width <= 0) btmrgtrc.Width = 1;
LinearGradientBrush btmrgt = new LinearGradientBrush(btmrgtrc,
uiprspty.fColor2, uiprspty.fColor1, LinearGradientMode.ForwardDiagonal);

g.FillRectangle(topleft, topleftrc);
g.FillRectangle(toprgt, toprgtrc);
g.FillRectangle(btmleft, btmleftrc);
g.FillRectangle(btmrgt, btmrgtrc);

topleft.Dispose();
toprgt.Dispose();
btmleft.Dispose();
btmrgt.Dispose();
#endregion

#region paint text
if (uiprspty.showText)
{
if (uiprspty.Text != null || uiprspty.Text.Trim() != "")
{
SizeF szf = g.MeasureString(uiprspty.Text, uiprspty.textFont);
int leftp = (int)szf.Width > uiprspty.Width ? 1 : (uiprspty.Width - (int)szf.Width) / 2;
int toppx = (int)szf.Height > uiprspty.Height ? 1 : (uiprspty.Height - (int)szf.Height) / 2;
g.DrawString(uiprspty.Text, uiprspty.textFont,
new SolidBrush(uiprspty.foreColor), (float)leftp, (float)toppx);
}
}
#endregion

//border
g.DrawRectangle(new Pen(uiprspty.borderColor),
new Rectangle(0, 0, uiprspty.Width - 1, uiprspty.Height - 1));

#region SaveMap
//ptr disponse
g.Dispose();
GC.Collect();

//save?
if (uiprspty.bSave)
{
try
{
map.Save(uiprspty.path, System.Drawing.Imaging.ImageFormat.Png);
uiprspty.bSaved = true;
}
catch
{
uiprspty.bSaved = false;
}
}
#endregion
return map;
}
}

public struct UIProgressProperty
{
public int Width;
public int Height;
public bool showText;
public string Text;
public Font textFont;
public Color foreColor;
public Color fColor1;
public Color fColor2;
public Color borderColor;
public Color backColor;

public int Value;
public int maxValue;

public bool bSave;
public bool bSaved;
public string path;

public void SetValueAndSave(int value, int maxvalue, bool save, string savepath)
{
Value = value;
maxValue = maxvalue;
bSave = save;
path = savepath;
}

public void SetThemeOrange(int ctlWidth, int ctlHeight)
{
Width = ctlWidth;
Height = ctlHeight;
showText = true;
textFont = new Font("Arial", 9f);
Text = "";
foreColor = Color.OrangeRed;
borderColor = Color.OrangeRed;
backColor = Color.White;
fColor1 = Color.Orange;
fColor2 = Color.White;
}
public void SetThemeGreen(int ctlWidth, int ctlHeight)
{
Width = ctlWidth;
Height = ctlHeight;
showText = true;
textFont = new Font("Arial", 9f);
Text = "";
foreColor = Color.Green;
borderColor = Color.Green;
backColor = Color.White;
fColor1 = Color.FromArgb(16, 217, 3);
fColor2 = Color.White;
}
}


[此贴子已经被作者于2007-10-29 12:03:14编辑过]

搜索更多相关主题的帖子: NET 进度 ASP 动态 
2007-10-29 12:01
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
就一个结构和一个类,现实的来说是一个函数。。。函数调用结构。不难.GDI。

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-10-30 07:53
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
这也不完全算是WEB。是和WIN共享。。。

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-10-30 20:15
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
public struct UIProgressProperty
是这个值,一个结构。保存着进度条的数据属性。

那个结构里面提供了两种默认的。你可以申明一个结构调用函数,自动生成样式。。。再BUILDEFAULT就有图了。

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-11-11 09:31
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 

是啊,他有GDI系统。。。



斑竹,帖子调用这个类的代码吧,我试了一晚上都没有见到效果
不死心!!!
不是吧?/LH。。。。得到图片可以用WEB的OUTPUT直接输出到网页。。
兄弟我帮你写个例子吧。。
UIProgressProperty uidata;
uidata.SetThemeGreen(100,18);//设置高度宽度
uidata.SetValueAndSave(99,100,true,"c:\\");//set value & maxvalue ..后两个参数设置为TRUE为保存文件到本地,。。路径
UIMaps map;
Image img=(Image)map.BuildDefault(uidata);
//OK图片得到了。后面随便你怎么处置图片了。是直接OUTPUT还是保存出来(已保存在C:\\)调用自己处理。


XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-11-12 08:09
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
以下是引用By1782在2007-11-12 16:39:30的发言:

谢谢 jacklee斑竹

我也懵了, 进度条生成也是用在操作时间比较长的地方使用哈
比如上传文件的时候是否可以显示他的进度
此时该如何调用它?

能否详细一些或者给个例子吧,小弟对这个类实在太有兴趣,但是整到现在还是没有弄明白!

不明白斑竹的得到图片后可以直接输出到网页上或者保存到本地,这个用处是什么?
照斑竹的方法试了一下,出错了,
Image是不明确的引用
using System.Drawing.Imaging;
using System.Drawing;
加了名字空间都不行!

跪谢了,等待中.........

大家如此关注,我今天中午写个DEMO吧,不过这只是静态的,可以拿来很好的显示比例有如此作用。如要改成动态进度,必须要用到ATLAS技术。你可以扩展写成组件就可以像WINDOWS一样了。


XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-11-14 07:38
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-11-16 09:10
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 

可以!


XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-11-19 08:06
快速回复:ASP.NET动态生成进度条图片
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022981 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved