|
Using Images
| [Previous] [Main] [Next] |
|
| |
| The htmlImage class encapsulates images in an html++ document, and is used to reference images stored in separate files. Numerous image file formats abound, but the two most popular formats for web browsers are GIF and JPEG. A third image format, called GIF89 or GIF89a (both collectively referred to as GIF files also), allows images to contain transparent colors while providing extensions to support simple animation (by layering multiple GIF's in a single file). GIF89 is commonly used to display animated banner advertisements on web pages.
| |
|
| |
| There are three kinds of images within documents:
| |
|
|
| |
| Static images are regular images on a page. Hyperlinked images are images embedded within a hyperlink, so that they can be clicked on by a user to load another document. Client-side image maps are images that contain one or more "hot spots" as hyperlinks.
| |
|
| |
| To place an image on a page, use the htmlImage class as follows:
| |
|
| |
| page << htmlImage( "/images/logo.gif" ) ;
| |
|
| |
| In case the image file is unavailable, or in case the user's browser doesn't diplay graphics (as is often the case with PDA's and other small computers), you should consider adding a description of the image as alternate text:
| |
|
| |
| page << htmlImage( "/images/logo.gif",
| |
| "logo description" ) ;
| |
|
| |
| The alternate text "logo description" will be displayed in lieu of the image if the browser is in text-only mode, or if the browser does not support images, or if the user suspends loading of the image.
| |
|
| |
| If the image dimensions are specified (using the Height() and Width() methods), many browsers will display a placeholder of the appropriate size while loading other page elements, instead of waiting for the image to load first. If you do this while specifying alternate text for the image, the user will also be able to view the alternate text until the image is fully loaded.
| |
|
| |
| Images can be aligned horizontally OR vertically, relative to their surroundings. The alignment setting can be specified in one of the constructors, or you can use the Align() or VAlign() methods. If you choose not to specify various parameters using the constuctors, you can use member methods instead:
| |
|
| |
| htmlImage logo ;
| |
| logo.Image( "/images/logo.gif" )
| |
| .AlternateText( "logo description" )
| |
| .VAlign( valign_middle ) ;
| |
|
| |
| page << logo ;
| |
|
| |
|
| |
|
| |
