|
-
Apr 2nd, 2000, 07:50 PM
#1
Thread Starter
Junior Member
Can anyone tell me how I can produce a blurred or out of focus effect on a VB form?
-
Apr 2nd, 2000, 09:59 PM
#2
Addicted Member
Here is how.
Put a picture (with Autoredraw:ON) in a form and put the following code to a button. It works like this:
Get a square tile of a picture (e.g 3x3). Get red, green, and blue value of each pixel in the square. Combine all red values and find the mean. Do the same with green and blue.
Then apply the new value in to the pixel in the center of the square.
Ex:
| 1 | 2 | 3 | Red(0) = (Red(1) + Red(2) + Red(3) + Red(4) + Red(5) + Red(6) + _
|---|---|---| Red(7) + Red(8) + Red(9)) / 9
| 4 | 5 | 6 | Green(0) = ..... (same as above)
|---|---|---| Blue(0) = ..... (same as above)
| 7 | 8 | 9 | Apply the RGB(Red(0), Green(0), Blue(0)) in to pixel 5.
Code:
Dim X(10)
Dim XX(10)
Dim RedA(10) As Integer
Dim GreenA(10) As Integer
Dim BlueA(10) As Integer
X1 = 1: Y1 = 1
X2 = Picture1.ScaleWidth - 1: Y2 = Picture1.ScaleHeight - 1
Y = 0
L = 0
For I = Y1 To Y2
For J = X1 To X2
RedB = 0: GreenB = 0: BlueB = 0
X(0) = Picture1.Point(J, I)
X(1) = Picture1.Point(J - 1, I - 1)
X(2) = Picture1.Point(J - 1, I)
X(3) = Picture1.Point(J - 1, I + 1)
X(4) = Picture1.Point(J, I - 1)
X(5) = Picture1.Point(J, I + 1)
X(6) = Picture1.Point(J + 1, I - 1)
X(7) = Picture1.Point(J + 1, I)
X(8) = Picture1.Point(J + 1, I + 1)
For D = 0 To 8
MHB = X(D) + 1
RedTemp = MHB Mod 256
AX = Int(MHB / 256)
GreenTemp = AX Mod 256
BlueTemp = Int(AX / 256)
RedA(D) = RedTemp - 1
If RedTemp = 0 Then RedA(D) = 0
GreenA(D) = GreenTemp
BlueA(D) = BlueTemp
Next D
For D = 0 To 8
RedB = RedB + RedA(D)
GreenB = GreenB + GreenA(D)
BlueB = BlueB + BlueA(D)
Next D
RedC = Int(RedB / 9)
GreenC = Int(GreenB / 9)
BlueC = Int(BlueB / 9)
If RedC < 0 Then RedC = 0
If GreenC < 0 Then GreenC = 0
If BlueC < 0 Then BlueC = 0
If RedC > 255 Then RedC = 255
If GreenC > 255 Then GreenC = 255
If BlueC > 255 Then BlueC = 255
Picture1.PSet (J, I), RGB(RedC, GreenC, BlueC)
Next J
Next I
PS- I need to change the contrast in a B/W picture anybody know how ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|