Results 1 to 3 of 3

Thread: Anti-aliasing

  1. #1

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Talking

    Hi kids, any one knows how to draw anti-aliased (smooth) lines, circles, ... in VB6?
    Should I implement some specific algorithms or does there exist some DLL?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Sure there are dll's for this, but i've once tried to make a antialiased circle, here's the sample:
    Code:
    Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    
    Private Sub Command1_Click()
    Dim dx&, dy&, X&, Y&, fade!, color1&, color2&, alpha&
         Picture = Image
        For Y = 1 To 200
            For X = 1 To 200
                dx = 100 - X
                dy = 100 - Y
                fade = Abs(100 - Sqr(dx * dx + dy * dy))
                If fade < 1 Then
                    color1 = GetPixel(hdc, X, Y)
                    color2 = vbRed
                    alpha = RGB((color1 Mod 256) * fade + (color2 Mod 256) * (1 - fade), (Int(color1 / 256) Mod 256) * fade + (Int(color2 / 256) Mod 256) * (1 - fade), Int(color1 / 65536) * fade + Int(color2 / 65536) * (1 - fade))
                    SetPixelV hdc, X, Y, alpha
                End If
            Next X
        Next Y
    End Sub
    Put a picture on the form and it will blend to the background.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    This is a blending module I made a while ago:

    Code:
    'To draw/extract pixels...
    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 Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    
    
    
    Private Type RGBColor
        Red As Integer
        Green As Integer
        Blue As Integer
    End Type
    
    
    Public Sub SmoothImage(TargetHDC As Long, Width As Long, Height As Long)
        
        ' -- These are the variables --
        
        'Loop counters and temporary variable for colors
        Dim cX As Long, cY As Long, TempColor As Long
        
        
        'Temporary variables for RGB values
        Dim R As Long, G As Long, B As Long
        
        'A version of the image with all the RGBs extracted
        Dim ImageRGB() As RGBColor
        
        
        
        ' -- Initializations... --
        
        'Resize the array
        ReDim ImageRGB(-1 To Width, -1 To Height)
        
        
        ' -- Get all the RGB values to an array --
        
        For cX = -1 To Width
            For cY = -1 To Height
                'Extract this pixel
                TempColor = GetPixel(TargetHDC, cX, cY)
                
                'If it's out of the image, make it transparent
                If cX = -1 Or cX = Width Or cY = -1 Or cY = Height Then TempColor = BGColor
                
                'Extract its RGBs
                ImageRGB(cX, cY).Red = TempColor And 255
                ImageRGB(cX, cY).Green = (TempColor And 65280) \ 256
                ImageRGB(cX, cY).Blue = (TempColor And 16711680) \ 65535
            Next cY
        Next cX
        
        
        
        ' -- Blend and draw them --
        
        For cX = 0 To Width - 1
            For cY = 0 To Height - 1
                
                
                
                
                
                'Get the average between all the surrounding colors
                R = (ImageRGB(cX, cY).Red + _
                  ImageRGB(cX + 1, cY).Red + _
                  ImageRGB(cX - 1, cY).Red + _
                  ImageRGB(cX, cY + 1).Red + _
                  ImageRGB(cX, cY - 1).Red + _
                  ImageRGB(cX - 1, cY - 1).Red + _
                  ImageRGB(cX + 1, cY + 1).Red + _
                  ImageRGB(cX + 1, cY - 1).Red + _
                  ImageRGB(cX - 1, cY + 1).Red) \ 9
                
                G = (ImageRGB(cX, cY).Green + _
                  ImageRGB(cX + 1, cY).Green + _
                  ImageRGB(cX - 1, cY).Green + _
                  ImageRGB(cX, cY + 1).Green + _
                  ImageRGB(cX, cY - 1).Green + _
                  ImageRGB(cX - 1, cY - 1).Green + _
                  ImageRGB(cX + 1, cY + 1).Green + _
                  ImageRGB(cX + 1, cY - 1).Green + _
                  ImageRGB(cX - 1, cY + 1).Green) \ 9
                
                B = (ImageRGB(cX, cY).Blue + _
                  ImageRGB(cX + 1, cY).Blue + _
                  ImageRGB(cX - 1, cY).Blue + _
                  ImageRGB(cX, cY + 1).Blue + _
                  ImageRGB(cX, cY - 1).Blue + _
                  ImageRGB(cX - 1, cY - 1).Blue + _
                  ImageRGB(cX + 1, cY + 1).Blue + _
                  ImageRGB(cX + 1, cY - 1).Blue + _
                  ImageRGB(cX - 1, cY + 1).Blue) \ 9
                
                'Now, draw this pixel with the new color
                SetPixel TargetHDC, cX, cY, RGB(R, G, B)
                
            Next cY
        Next cX
        
        'Show the default pointer
        Screen.MousePointer = vbDefault
    End Sub
    Not sure if it's correct, had to do some last-minute changes...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width