很多抗锯齿的方法只适合于画直线之类的!

解决方案 »

  1.   

    if 你可以抗锯齿画直线 then
       你同样可以抗锯齿画圆
    else
       你根本就没有弄懂抗锯齿的算法,建议你好好看看抗锯齿画直线的算法
    end if
      

  2.   

    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 / 180Private 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 SubPrivate 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
      

  3.   

    修正一下
    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