首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请问一个关于gdi+渐变的有关问题

2012-04-21 
请教一个关于gdi+渐变的问题我用html5画圆,并且是渐变,然后用c#画圆时,渐变色总是不一致,代码如下:HTML部

请教一个关于gdi+渐变的问题
我用html5画圆,并且是渐变,然后用c#画圆时,渐变色总是不一致,代码如下:
HTML部分

HTML code
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title></head><body onload="">    <canvas id="myCanvas" width="500" height="500">    Your browser does not support the canvas element.    </canvas>    <script type="text/javascript">        function tt()        {            var c = document.getElementById("myCanvas");            var cxt = c.getContext("2d");            var radGrad = cxt.createRadialGradient(200, 200, 0, 200, 200, 100);            radGrad.addColorStop(0.0, 'rgba(0,0,255,1)');            radGrad.addColorStop(1.0, 'rgba(0,0,0,0)');            cxt.fillStyle = radGrad;            cxt.fillRect(0, 100, 400, 200);        }        tt();    </script></body></html>



后台C#部分
C# code
protected void Page_Load(object sender, EventArgs e)        {            Bitmap bmp = new Bitmap(200, 200);            Graphics g = Graphics.FromImage(bmp);            Color cStart = Color.FromArgb(40, 0, 0, 0);            Color cEnd = Color.FromArgb(255, 0, 0, 255);            int radius = 100;            GraphicsPath path = new GraphicsPath();            path.AddEllipse(0, 0, radius * 2, radius * 2);            PathGradientBrush pthGrBrush = new PathGradientBrush(path);            pthGrBrush.CenterColor = cEnd;            Color[] colors = { cStart };            pthGrBrush.SurroundColors = colors;            g.FillEllipse(pthGrBrush, 0, 0, radius * 2, radius * 2);            bmp.Save("d:\\1.png");            bmp.Dispose();            g.Dispose();        }


求高手指导下,解决立刻给分

[解决办法]
为啥不一样不知道,要不你用 LinearGradientBrush
 试试渐变色?
[解决办法]
...... path的渐变色阿。。。
[解决办法]
protected void Page_Load(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(200, 200);
Graphics g = Graphics.FromImage(bmp);
Color cStart = Color.FromArgb(40, 0, 0, 0);
Color cEnd = Color.FromArgb(255, 0, 0, 255);
int radius = 100;
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, radius * 2, radius * 2);
PathGradientBrush pthGrBrush = new PathGradientBrush(path);
pthGrBrush.CenterColor = cEnd;
Color[] colors = { cStart };
pthGrBrush.SurroundColors = colors;
g.FillEllipse(pthGrBrush, 0, 0, radius * 2, radius * 2);
bmp.Save("d:\\1.png");
bmp.Dispose();
g.Dispose();

}




[解决办法]
Color cStart = Color.FromArgb(40, 0, 0, 0); //alpha是否要为0?


探讨
或者path渐变是否能实现多种颜色的渐变?比如中心红色,中间位黄色,边上为蓝色?调试半天没有效果

[解决办法]
Gradients made easy

热点排行