如何绘制圆形渐变? [英] How do I draw a circular gradient?

查看:149
本文介绍了如何绘制圆形渐变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绘制圆形渐变像这样在vb.net中?

How do I draw a circular gradient like this in vb.net?

推荐答案

查看此很棒的页面.本文中的代码在C#中.这是您感兴趣的代码的vb.net端口,并针对矩形填充进行了更新:(基于文章的三角形填充示例.)

Check out this great page. The code in the article is in C#. Here is a vb.net port of the code you'e interested in and updated for a rectangular fill: (based on the article's triangle fill sample.)

    Dim pgb As New PathGradientBrush(New Point() { _
        New Point(0, 0), _
        New Point(0, Me.ClientRectangle.Height), _
        New Point(Me.ClientRectangle.Width, Me.ClientRectangle.Height), _
        New Point(Me.ClientRectangle.Width, 0)})
pgb.SurroundColors = New Color() {Color.Red}
pgb.CenterColor = Color.Gray
e.Graphics.FillRectangle(pgb, Me.ClientRectangle)
pgb.Dispose()

这是另一种可能的解决方案:

Here's another possible solution:

Dim pth As New GraphicsPath()
pth.AddEllipse(Me.ClientRectangle)
Dim pgb As New PathGradientBrush(pth)
pgb.SurroundColors = New Color() {Color.Red}
pgb.CenterColor = Color.Gray
e.Graphics.FillRectangle(pgb, Me.ClientRectangle)

请注意,这最后一个代码段将在矩形内部绘制一个有界的圆.如果要使圆形渐变填充整个矩形,则必须计算具有较大矩形的较大椭圆路径.

Note that this last code snippet will draw a circle bounded inside of a rectangle. If you want the circular gradient to fill the entire rectangle you'll have to calculate a larger elliptic path with a larger rectangle.

这篇关于如何绘制圆形渐变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆