Draw circles in anti-aliasing mode!

Source: Internet
Author: User

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 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

Private sub commandementclick ()
Circleex pic, 100,100, 50, vbred
PIC. Refresh
End sub
 

 

When you draw a line in this way, you must note that the slope is greater than or less than 1. Here we will not go into details!

If you think the color of the circle is different from the specified color, modify the last transparency parameter of setpixel in the last four rows of the psetex function, for example, multiply by 2 !.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.