Search In Site

01 July, 2013

Blurring And Sweeping Images in Visual Basic


Sweeping Images
When we created embossed and engraved images in the previous two topics, we were careful to set up our embossing or engraving loop so that when setting a pixel, we did not make use of other pixels that we had already
set in the same loop. 
The reason for that is that we only wanted to plot the difference between adjacent pixels that is, the difference between two pixels only to create embossed or engraved images. If we had not restricted our operation to two pixels we had not already worked on, and instead worked on pixels we had already set earlier, we could end up propagating a pixel’s color values among several other pixels. That is, one pixel’s setting could affect many other pixels.
In fact, there are times when you want to have that happen—for example, you might want to make an image appear as though it is sweeping from upper-left to lower-right, giving the illusion of motion. In that case, you’d copy pixels with the ones to the upper-left over and over, progressively blending them together to create the effect, where it looks as though the text has a fading trail of color behind it.
we move from lower-right to upper-left, averaging each pixel with the one to the lower-right:
For x = intUpperBoundX – 1 To 1 Step –1
For y = intUpperBoundY – 1 To 1 Step –1
bytRed = Abs((Pixels(x + 1, y + 1) And &HFF) + (Pixels(x, y)_
And &HFF)) / 2
bytGreen = Abs(((Pixels(x + 1, y + 1) And &HFF00) / &H100)_
Mod &H100 + ((Pixels(x, y) And &HFF00) / &H100) Mod_
&H100) / 2
bytBlue = Abs(((Pixels(x + 1, y + 1) And &HFF0000) / &H10000) _
Mod &H100 + ((Pixels(x, y) And &HFF0000) / &H10000) Mod_
&H100) / 2
Pixels(x, y) = RGB(bytRed, bytGreen, bytBlue)
Next y
Next x
That’s all it takes—now we copy the image into the second picture box,  picture2. (To be able to work pixel by pixel, make sure you set each picture box’s ScaleMode property to vbPixel (3).) By combining successive pixels
as we do in this example, we create the sweeping effect. Now we’re creating complex images using image handling techniques. 

Blurring Images
The Aesthetic Design Department is calling again. If you’re going to add image effects to your program, SuperDuperGraphicsPro, why not let the user blur images? You can blur images by averaging pixels. To see how this works, we load the pixels from a picture box, Picture1, and blur them, then display the result in another picture box, Picture2. To be able to work pixel by pixel, set each picture box’s ScaleMode property to vbPixel (3). As with the code in the previous few topics in this chapter, we load the pixels from Picture1 into an array named Pixels. To blur the pixels, you average them together; here, we just average each pixel with the next pixel to the right , but you can set up any blurring region you like (such as all eight pixels that surround the  current pixel). This is the way our blurring process looks in code:
For x = 1 To intUpperBoundX – 1
For y = 1 To intUpperBoundY
bytRed = Abs((Pixels(x + 1, y) And &HFF) + (Pixels(x, y) _
And &HFF)) / 2
bytGreen = Abs(((Pixels(x + 1, y) And &HFF00) / &H100) Mod _
&H100 + ((Pixels(x, y) And &HFF00) / &H100) Mod &H100) / 2
bytBlue = Abs(((Pixels(x + 1, y) And &HFF0000) / &H10000) _
Mod &H100 + ((Pixels(x, y) And &HFF0000) / &H10000)_
Mod &H100) / 2
Pixels(x, y) = RGB(bytRed, bytGreen, bytBlue)
Next y
Next x

0 comments:

Post a Comment

Dear Visitors All The Tricks And Hacks Posted Here Are Only For Knowledge Purpose.Don't Use These for Illegal Operations.

 
Twitter Bird Gadget