OK, what's HDC of a picturebox?
I've found this on the forum:
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.
It's from:
http://www.vbforums.com/showthread.p...light=blurring
Hoe do I call this function?