Visual Basic 6 Black Book:Working With Images
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
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 pixelsthat is, the difference between two pixels onlyto 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 pixels color values among several other pixels. That is, one pixels setting could affect many other pixels.
In fact, there are times when you want to have that happenfor 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, youd copy pixels with the ones to the upper-left over and over, progressively blending them together to create the effect you see in Figure 19.16, where it looks as though the text has a fading trail of color behind it.
Figure 19.16 Sweeping an image by working pixel by pixel.
Seeing the code that gives us the image in Figure 19.16 will help make this effect easier to understand. As with the previous few topics in this chapter, we load the image in a picture box, Picture1, into an array named Pixels. Then 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
Thats all it takesnow we copy the image into the second picture box, Picture2. (To be able to work pixel by pixel, make sure you set each picture boxs ScaleMode property to vbPixel (3).) By combining successive pixels as we do in this example, we create the sweeping effect you see in Figure 19.16. Now were creating complex images using image handling techniques.
The complete code for this example is located in the imagesweep folder on this books accompanying CD-ROM.
Blurring Images
The Aesthetic Design Department is calling again. If youre 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 boxs 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
After the pixels have been blurred, we display the result in Picture2, as shown in Figure 19.17. As you can see, the blurring produced with this algorithm is slight; to blur the image more, you can apply the same algorithm again or increase the number of pixels over which you average.
Figure 19.17 Blurring an image by working pixel by pixel.
The code for this example is located in the imageblur folder on this books accompanying CD-ROM.
Freeing Memory Used By Graphics
The Testing Department is calling again. Your program, SuperDuperGraphicsPro, is using up a lot of memory. Is there any way to free some memory when youre not using it anymore?
Yes, there is. When you are no longer using a picture in the Picture property of a form, picture box, or image control, set the Picture property to the Visual Basic Nothing keyword to empty it:
Set Picture1.Picture = Nothing
In addition, if you use the Image property of a picture box or form, Visual Basic creates an AutoRedraw bitmap (this happens even if the AutoRedraw property for that form or picture box is False). When youve finished using the Image property, you can empty the memory used by that bitmap with the Cls method before you set AutoRedraw to False, as in this example:
Picture1.AutoRedraw = True
Picture1.Cls
Picture1.AutoRedraw = False
Previous
Table of Contents
Next
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.
Wyszukiwarka
Podobne podstrony:
645 648demo cgi 648645 Informacja dodatkowa wprowadzenie do sprawozdania finasowego648 Badanie, ogłaszanie i zatwierdzanie sprawozdania finasowegoNuestro Círculo 645 UN SALVAJENokia? 00 RM 645 SM L1L2 v1 0645 (2)index (645)645,41,artykul641 645Nuestro Círculo 648 TORNEO TATA STEEL 2015więcej podobnych podstron