dcsimg
Results 1 to 4 of 4

Thread: Blurring

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    33
    I need a sub that will blur an image in a picture box by an amount that can be passed in the parameters. Thanks!

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    I have never tried myself, but I have seen in the forum that AnimateWindow can produce some kind of blurring. If you do succeed, then post the message.

    Thanks

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    I don't know why people ask big questions like this... The only answer is, learn to program.
    Here's an example of it.http://www.planet-source-code.com/xq...s/ShowCode.htm
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  4. #4
    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

    Cool Hum, the code of StuPaint is a bit messy, here's some code by me

    Paste this into a module:

    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)
                
                '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)
                
                'End If
            Next cY
        Next cX
    End Sub
    This way just call the function with the PictureBox's HDC, Width and Height.

    It's much smoother than StuPaint's too! If it's for a painting program, give the user the option "Blurring Factor", and repeat the process that number of times to blur it even more.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width