如何画圆,使圆内的颜色为渐变色

zx095x 2010-10-16 05:27:15
我是这样画圆的。只能填充一种颜色,希望填充渐变色:
    Picture1.FillStyle = 0
Picture1.FillColor = RGB(160, 130, 0) '外圈填充色

Picture1.DrawWidth = 1
Picture1.Circle (BaseX, BaseY), printR2 * 1.3, RGB(143, 122, 16) '画外圈圆
...全文
789 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
贝隆 2010-10-16
  • 打赏
  • 举报
回复
18037803
zx095x 2010-10-16
  • 打赏
  • 举报
回复
要求左上角最淡,怎么改?有QQ么?

[Quote=引用 21 楼 veron_04 的回复:]
上面是按右侧45°渐变
[/Quote]
贝隆 2010-10-16
  • 打赏
  • 举报
回复
上面是按右侧45°渐变
贝隆 2010-10-16
  • 打赏
  • 举报
回复
可按45°变换,picMap是PictureBox的名字,我按自己的习惯改了名称。

Option Explicit
Private Const PI = 3.1415926
Private Sub btnDrawCircle_Click()
Dim intR As Integer '圆的半径
Dim intRed As Integer 'RGB的R
Dim intGreen As Integer 'RGB的G
Dim intBlue As Integer 'RGB的B
Dim intP As Long
Dim X1 As Double
Dim Y1 As Double
Dim X2 As Double
Dim Y2 As Double
Dim delta As Double
Dim lngCount As Long
On Error GoTo errSub
intR = 2000
intRed = 143
intGreen = 122
intBlue = 16
lngCount = 1000
Rem 细分数:lngCount
delta = PI / lngCount
For intP = 0 To lngCount
X1 = intR * Cos(delta * intP + PI * 0.25)
Y1 = intR * Sin(delta * intP + PI * 0.25)
X2 = intR * Cos(-delta * intP + PI * 0.25)
Y2 = intR * Sin(-delta * intP + PI * 0.25)
picMap.Line (X1, Y1)-(X2, Y2), RGB(intRed / lngCount * intP, intGreen / lngCount * intP, intBlue / lngCount * intP)
Next intP
Exit Sub
errSub:
End Sub

Private Sub Form_Load()
With picMap
.Appearance = 0
.AutoRedraw = True
.FillStyle = 1
.DrawMode = 13
.DrawWidth = 1
.Width = 8000
.Height = 6000
End With
picMap.Scale (-4000, 3000)-(4000, -3000) '定义坐标系统,图片正中心是(0,0)
End Sub

ao5212 2010-10-16
  • 打赏
  • 举报
回复
都是高人 学习了
zx095x 2010-10-16
  • 打赏
  • 举报
回复
能按上图45度角渐变么?

[Quote=引用 17 楼 zx095x 的回复:]
运行不了,不知道picMap是啥


引用 16 楼 veron_04 的回复:
上面的是从右到左的渐变效果
这个是从上到下的渐变效果

VB code

Option Explicit
Private Const PI = 3.1415926
Private Sub btnDrawCircle_Click()
Dim intR As Integer '圆的半径
Dim ……
[/Quote]
zx095x 2010-10-16
  • 打赏
  • 举报
回复
运行不了,不知道picMap是啥

[Quote=引用 16 楼 veron_04 的回复:]
上面的是从右到左的渐变效果
这个是从上到下的渐变效果

VB code

Option Explicit
Private Const PI = 3.1415926
Private Sub btnDrawCircle_Click()
Dim intR As Integer '圆的半径
Dim intRed As Integer 'RGB的R
D……
[/Quote]
贝隆 2010-10-16
  • 打赏
  • 举报
回复
上面的是从右到左的渐变效果
这个是从上到下的渐变效果

Option Explicit
Private Const PI = 3.1415926
Private Sub btnDrawCircle_Click()
Dim intR As Integer '圆的半径
Dim intRed As Integer 'RGB的R
Dim intGreen As Integer 'RGB的G
Dim intBlue As Integer 'RGB的B
Dim intP As Long
Dim X1 As Double
Dim Y1 As Double
Dim X2 As Double
Dim Y2 As Double
Dim delta As Double
Dim lngCount As Long
On Error GoTo errSub
intR = 2000
intRed = 143
intGreen = 122
intBlue = 16
lngCount = 1000
Rem 细分数:lngCount
delta = PI / lngCount
For intP = 0 To lngCount
X1 = intR * Cos(delta * intP + PI * 0.5)
Y1 = intR * Sin(delta * intP + PI * 0.5)
X2 = intR * Cos(-delta * intP + PI * 0.5)
Y2 = intR * Sin(-delta * intP + PI * 0.5)
picMap.Line (X1, Y1)-(X2, Y2), RGB(intRed / lngCount * intP, intGreen / lngCount * intP, intBlue / lngCount * intP)
Next intP
Exit Sub
errSub:
End Sub

Private Sub Form_Load()
With picMap
.Appearance = 0
.AutoRedraw = True
.FillStyle = 1
.DrawMode = 13
.DrawWidth = 5
.Width = 8000
.Height = 6000
End With
picMap.Scale (-4000, 3000)-(4000, -3000) '定义坐标系统,图片正中心是(0,0)
End Sub
h3225518 2010-10-16
  • 打赏
  • 举报
回复
厉害啊
贝隆 2010-10-16
  • 打赏
  • 举报
回复

Option Explicit
Private Const PI = 3.1415926
Private Sub btnDrawCircle_Click()
Dim intR As Integer '圆的半径
Dim intRed As Integer 'RGB的R
Dim intGreen As Integer 'RGB的G
Dim intBlue As Integer 'RGB的B
Dim intP As Long
Dim X1 As Double
Dim Y1 As Double
Dim X2 As Double
Dim Y2 As Double
Dim delta As Double
On Error GoTo errSub
intR = 2000
intRed = 143
intGreen = 122
intBlue = 16
Rem 细分数:1000
delta = PI / 1000
For intP = 0 To 1000
X1 = intR * Cos(delta * intP)
Y1 = intR * Sin(delta * intP)
X2 = intR * Cos(-delta * intP)
Y2 = intR * Sin(-delta * intP)
picMap.Line (X1, Y1)-(X2, Y2), RGB(intRed / 1000 * intP, intGreen / 1000 * intP, intBlue / 1000 * intP)
Next intP
Exit Sub
errSub:
End Sub

Private Sub Form_Load()
With picMap
.Appearance = 0
.AutoRedraw = True
.FillStyle = 1
.DrawMode = 13
.DrawWidth = 5
.Width = 8000
.Height = 6000
End With
picMap.Scale (-4000, 3000)-(4000, -3000) '定义坐标系统,图片正中心是(0,0)
End Sub


这个方法效率比较低,但很好理解。
zx095x 2010-10-16
  • 打赏
  • 举报
回复
无代码无真相

[Quote=引用 12 楼 lyserver 的回复:]
使用GDI+渐变色画笔或GDI中的CreatePatternBrush函数创建一个渐变色画刷填充即可。
[/Quote]
lyserver 2010-10-16
  • 打赏
  • 举报
回复
使用GDI+渐变色画笔或GDI中的CreatePatternBrush函数创建一个渐变色画刷填充即可。
zx095x 2010-10-16
  • 打赏
  • 举报
回复
zx095x 2010-10-16
  • 打赏
  • 举报
回复
前面 说过了,是 自上向下渐变

[Quote=引用 9 楼 veron_04 的回复:]
VB code

Private Sub Command1_Click()
Dim bytR As Byte
Dim bytG As Byte
Dim bytB As Byte
Dim hBrush As Long
Dim OldMode As Integer
Dim RetVal As Integer
Dim StepSi……
[/Quote]
贝隆 2010-10-16
  • 打赏
  • 举报
回复

Private Sub Command1_Click()
Dim bytR As Byte
Dim bytG As Byte
Dim bytB As Byte
Dim hBrush As Long
Dim OldMode As Integer
Dim RetVal As Integer
Dim StepSize As Integer
Dim X As Integer
Dim FillArea As RECT

Dim BaseX As Long
Dim BaseY As Long
Dim R2 As Long
Dim lngP As Long

Picture1.AutoRedraw = True
R2 = 1000
BaseX = 0.5 * Picture1.Width
BaseY = 0.5 * Picture1.Height
Picture1.DrawWidth = 1
For X = 255 To 1 Step -1
Picture1.Circle (BaseX, BaseY), (R2 / 255) * X, RGB(X, 0, 0)
Next X
Picture1.Refresh
End Sub

这个方法比较简单,就是一圈一圈的绘制园,越细分效果越好。
zx095x 2010-10-16
  • 打赏
  • 举报
回复
我不会改啊

[Quote=引用 6 楼 bcrun 的回复:]
楼主你没仔细看他的代码,他那个圆圈好像也是用的线性渐变,是多个三角形拼起来的.

当然,你如只需要直接从上到下渐变的,参考他这个代码就行了,注意,我在后面补充的参数(默认值是水平方向的)GRADIENT_FILL_RECT_V


VB code
Private Sub Command2_Click()
DrawGradientRect Me.hDC, 10, 10, 200……
[/Quote]
贝隆 2010-10-16
  • 打赏
  • 举报
回复
填充的思想就是将圆细微划分成很多部分,每个部分填充不同的颜色,颜色之间是渐渐变化的。
bcrun 2010-10-16
  • 打赏
  • 举报
回复
楼主你没仔细看他的代码,他那个圆圈好像也是用的线性渐变,是多个三角形拼起来的.

当然,你如只需要直接从上到下渐变的,参考他这个代码就行了,注意,我在后面补充的参数(默认值是水平方向的)GRADIENT_FILL_RECT_V

Private Sub Command2_Click()
DrawGradientRect Me.hDC, 10, 10, 200, 100, vbBlue, vbGreen, GRADIENT_FILL_RECT_V
Me.Refresh
End Sub
zx095x 2010-10-16
  • 打赏
  • 举报
回复
谢谢这位朋友,俺想要的是从上到下渐变,不是这种同心渐变

[Quote=引用 2 楼 hnuqinhuan 的回复:]
路过 顶
[/Quote]
游子 2010-10-16
  • 打赏
  • 举报
回复
顶楼上。。。。。。。。。。
加载更多回复(1)

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧