Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Graphics
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 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
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
Yes, I know that this sounds complicated. Lets take a look at the syntax of the PaintPicture method
object.PaintPicture source, x1, y1, w1, h1, x2, y2, w2, h2, opcode
where the arguments are as follows:
objectThe name of the Picture Box, Form, or Printer object where the picture is to be placed. This argument is optional. If its omitted, the form with the focus is assumed.
sourceThe source of the graphic. Must be the Picture property of a Form, Picture, or Picture Box object.
x1, y1Single-precision values indicating the destination coordinatesin other words, the location on the destination object where the top-left corner of the image is to be drawn. The ScaleMode property of the object determines the unit of measure used.
w1, h1Single-precision values indicating the destination width and height of the picture, using units specified by the ScaleMode property of the destination object. If the destination width and/or height is larger or smaller than the source width (w2) or height (h2), the picture is stretched or compressed to fit. These arguments are optional; if theyre omitted, the source width (w1) and height (h1) are used with no stretching or compression.
x2, y2Single-precision values indicating the source coordinates of the region in the source object that is to be copied (in units specified by the source objects ScaleMode property). These arguments are optional; if theyre omitted, 0 is assumed (indicating the top-left corner of the source image).
w2, h2Single-precision values indicating the width and height of the region within the source that is to be copied (in units specified by the source objects ScaleMode property). These arguments are optional; if theyre omitted, the entire source width and height are used.
opcodeA type Long value that defines the bitwise operation performed between the pixels of the source picture and the pixels of any existing image on the destination (explained shortly). This argument, which is optional, is useful only with bitmaps. If the argument is omitted, the source is copied onto the destination, replacing anything that is there.
Think of the source picture as being printed on a rubber sheet. You can cut out any rectangular part of the picture you want, stretch it vertically and/or horizontally, and stick it down anywhere on the destination picture. Sound useful? You bet it is. The operation of PaintPicture is illustrated in Figure 12.6.
The opcode argument can be a bit confusingwith good reason. How many ways can you copy a picture from one location to another? Well, you would be surpriseddozens, at least. Heres how it works: In the destination object, where the copied picture is going to be placed, an image already exists. A bitmap picture may be displayed there already, but even if the destination is blank, something is thereperhaps just white pixels. Over the extent of the copied region, therefore, each pixel in the copied image has a corresponding pixel at the same location in the destination. How will these pixels be combined? This is what the opcode argument determines.
Figure 12.6 The PaintPicture methods arguments.
The simplestand perhaps most commonoperation is to have each new pixel replace the original pixel. The opcode argument for this is the predefined constant vbSrcCopy. Two other useful opcode arguments are vbBlackness and vbWhiteness, which turn the destination rectangle all black or all white. This really isnt a copy of the source picture, of course; you still have to specify a source in the PaintPicture statement. Other opcode arguments perform a variety of logical combinations of the source picture with the destination picture. You can use them to create certain types of visual effects, but I wont go into them here. You can explore the topic further in the Visual Basic Help system.
TIP: Hiding The Picture Box
Dont forget that you can set a Picture Boxs Visible property to False, so it does not display on screen. Even while hidden, it is still a valid source for the PaintPicture method, and you can still load pictures into it by setting its Picture property or by using the LoadPicture statement.
The best way to get a feel for how PaintPicture works is to see it in action. The example program PAINTPIC demonstrates three common uses for this statement: enlarging a picture, shrinking a picture, and painting areas with black or white. To start the project, place two Picture Box controls on a form. For the first one (Picture1), set the AutoSize property to True, then load the picture GUARD.JPG (provided on the companion CD-ROM) into its Picture property. All of the properties for Picture2 should be left at their default values. Change the forms Caption property to Picture Magnifier.
The program requires three constants, placed in the general declarations section of the forms code. Two of the constants specify the vertical and horizontal magnification, expressed as the portion of the original picture that will be blown up. I used 0.3 for both the vertical and horizontal values; you can experiment with other values if you like. The third constant is the opcode vbWhiteness. Unfortunately, this is not predefined by Visual Basicwe have do it ourselves. The declarations code is shown here:
Option Explicit
Const vbWhiteness = &HFF0062
Const WIDE = 0.3
Const HIGH = 0.3
Adjusting the form and control sizes is accomplished in the Form_Load event procedure. Picture1 will already be the size of the loaded picture, because we set its AutoSize property to True. The following code makes the form size a bit taller than and a bit more than twice as wide as this Picture Box. Then it makes Picture2 the same size as Picture1 and positions them both on the form. The code is shown in Listing 12.4.
Listing 12.4 The Picture Magnifiers Form_Load procedure.
Private Sub Form_Load()
Form1.Width = 2.1 * Picture1.Width
Form1.Height = 1.1 * Picture1.Height
Picture1.Left = 0
Picture1.Top = 0
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
Picture2.Top = 0
Picture2.Left = Form1.ScaleWidth - Picture2.Width
End Sub
The real action will be triggered by the user clicking on the source picture. A left-button click will trigger the display (in the second Picture Box) of a magnified portion of the picture centered on the location where the mouse was clicked. A right-button click will display nine small copies of the entire picture, each surrounded by a black and white border.
Lets deal with detecting the click first. While the Click event procedure might seem like the way to go, a quick examination reveals that it provides no way to tell which button was clicked or where the mouse pointer was located. Clearly, we need something else. Scanning through the list of events that the Picture Box control supports, you will notice MouseDown and MouseUp events. The MouseUp event procedure declaration looks like this:
Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As
Single)
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. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
12 06 10 03 12 06 pra18 12 0619 12 06Test z ZS rozwiązywany z dr 12 06kolos pytania 12 06Informatyka 12 06 201212 06 Roboty szklarskieBagdad szef Irackiego Frontu Zgody nie żyje (12 06 2009)Programowanie C laborki c 5 12 0612 06kalendarium 12 0612 12 06 drzewao organizacjach pracodawców 12 06 2012re91001 12 06(A2FM)więcej podobnych podstron