如何以抗锯齿的方式画圆?

wuqiaowuqiao 2007-04-05 01:33:25
很多抗锯齿的方法只适合于画直线之类的!
...全文
647 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
laviewpbt 2007-04-17
  • 打赏
  • 举报
回复
修正一下
Private Sub CircleEx(Pic As PictureBox, CenterX As Long, CenterY As Long, Radius As Long, Optional Color As Long = vbRed)
Dim i As Single
Dim X As Single, Y As Single
For i = 0 To 360 Step 60 / Radius
X = Cos(i * PI)
Y = Sin(i * PI)
X = X * Radius + CenterX
Y = Y * Radius + CenterY
PsetEx Pic, X, Y, Color
Next
End Sub
laviewpbt 2007-04-17
  • 打赏
  • 举报
回复


Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
'
Private Const PI = 3.1415926 / 180

Private Sub PsetEx(Pic As PictureBox, X As Single, Y As Single, Optional Color As Long = 0)
Dim CenterX As Long, CenterY As Long, CenterColor As Long, CenterAlpha As Single
Dim CenterRX As Long, CenterRY As Long, CenterRColor As Long, CenterRAlpha As Single
Dim CenterBX As Long, CenterBy As Long, CenterBColor As Long, CenterBAlpha As Single
Dim CenterRBX As Long, CenterRBY As Long, CenterRBColor As Long, CenterRBAlpha As Single
Dim hDC As Long
hDC = Pic.hDC
CenterX = Int(X)
CenterY = Int(Y)
CenterColor = GetPixel(hDC, CenterX, CenterY)
CenterAlpha = (CenterX - X + 1) * (CenterY - Y + 1)
CenterRX = CenterX + 1
CenterRY = Int(Y)
CenterRColor = GetPixel(hDC, CenterRX, CenterRY)
CenterRAlpha = (X - CenterRX + 1) * (CenterY - Y + 1)
CenterBX = CenterX
CenterBy = CenterY + 1
CenterBColor = GetPixel(hDC, CenterBX, CenterBy)
CenterBAlpha = (CenterX - X + 1) * (Y - CenterBy + 1)
CenterRBX = CenterX + 1
CenterRBY = CenterY + 1
CenterRBColor = GetPixel(hDC, CenterRBX, CenterRBY)
CenterRBAlpha = (X - CenterRX + 1) * (Y - CenterBy + 1)
SetPixel hDC, CenterX, CenterY, BlendColor(CenterColor, Color, CenterAlpha)
SetPixel hDC, CenterRX, CenterRY, BlendColor(CenterRColor, Color, CenterRAlpha)
SetPixel hDC, CenterBX, CenterBy, BlendColor(CenterBColor, Color, CenterBAlpha)
SetPixel hDC, CenterRBX, CenterRBY, BlendColor(CenterRBColor, Color, CenterRBAlpha)
End Sub
'

Private Sub GetRGB(Color As Long, Red As Long, Green As Long, Blue As Long)
If Color <> 0 Then
Red = Color And 255&
Green = Color \ 256 And 255
Blue = Color \ 65536
End If
End Sub



Private Function BlendColor(ColorBase As Long, ColorBlend As Long, Alpha As Single) As Long
Dim BaseR As Long, BaseG As Long, BaseB As Long
Dim BlendR As Long, BlendG As Long, BlendB As Long
GetRGB ColorBase, BaseR, BaseG, BaseB
GetRGB ColorBlend, BlendR, BlendG, BlendB
If Alpha > 1 Then Alpha = 1
BaseR = Alpha * (BlendR - BaseR) + BaseR
BaseG = Alpha * (BlendG - BaseG) + BaseG
BaseB = Alpha * (BlendB - BaseB) + BaseB
BlendColor = RGB(BaseR, BaseG, BaseB)
End Function
'

Private Sub CircleEx(Pic As PictureBox, CenterX As Long, CenterY As Long, Radius As Long, Optional Color As Long = vbRed)
Dim i As Long
Dim X As Single, Y As Single
For i = 0 To 360
X = Cos(i * PI)
Y = Sin(i * PI)
X = X * Radius + CenterX
Y = Y * Radius + CenterY
PsetEx Pic, X, Y, Color
Next
End Sub


Private Sub Command1_Click()
CircleEx Pic, 100, 100, 50, vbRed
Pic.Refresh
End Sub

IamDeane 2007-04-10
  • 打赏
  • 举报
回复
if 你可以抗锯齿画直线 then
你同样可以抗锯齿画圆
else
你根本就没有弄懂抗锯齿的算法,建议你好好看看抗锯齿画直线的算法
end if

7,763

社区成员

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

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