| Methods Index |
Subclasses: None
CImage encapsulates the usage of XVT portable images. XVT's portable images feature lets your application manipulate, display, and print bitmapped graphic images in several different file formats. You can create images on the platform(s) of your choice and easily move them to other platforms.Your application can use images created on different GUI environments because XVT-Power++ methods can read several different image file formats. XVT supports the following formats:
Because the native graphics systems of the XVT-supported platforms use different standard formats, XVT has established the MS-Windows BMP format as the portable image file format for all XVT products. The XVT Portability Toolkit can display MS-Windows BMP images on any supported platform, automatically making any necessary conversions.
Note: Reading and writing of Macintosh PICT formats is supported on the Macintosh only.
Color
All XVT graphics, image, and pixmap operations use a red-green-blue (RGB) color model.
|
|
|
|
| Format | Displayable Colors | Memory per Pixel |
| Monochrome | Two (black and white) | One bit |
| Indexed | Up to 256 | One byte |
| True color | Up to 16 million |
One COLOR value (32 bits; 8 are not currently used)
|
COLOR entries. As a result, an image or pixmap that uses indexed color can contain up to 256 different colors simultaneously.
XVT_IMAGE_FORMAT enumerated type defines four values for the color formats available for images:
|
|
|
| XVT_IMAGE_* values: | Format: |
XVT_IMAGE_NONE
| No color |
XVT_IMAGE_CL8
|
Indexed color
|
XVT_IMAGE_RGB
|
True color
|
XVT_IMAGE_MONO
|
Monochrome
|
Note:
XVT_IMAGE_CL8 is the only format that has a color look-up table.
Image Coordinates
A CImage always has an origin of 0,0; the CPoint and CRect used by a CImage are relative to 0,0. Reading and Writing Model
The XVT-Power++ provides methods for reading and writing several different common image file formats as well as I/O stream objects. The writing methods store the specified image file or I/O stream object in a file format compatible with the MS-Windows BMP format. However, on the Macintosh you can read and write to Macintosh PICT files.
Usage
The following examples illustrate several uses of CImage:Constructing an Image
CImage anImage("file.bmp");
// from a file
CImage anImage(myData->itsXVTStream);
// from XVT_IOSTREAM
CImage anImage(XVT_IMAGE_CL8, 100, 100);
// width=height=100
CImage anImageCopy(anOriginalImage);
// from an existing image
CImage anImage(aPiXMap);
// from an XVT_PIXMAP
CImage anImage = anExistingImageID;
// will consume XVT_IMAGE
CImage anImage is an empty constructor. It does not create an image, so it is not valid. Use this constructor when reading a file of an unknown type, like this:
struct Tools {
CImage itsImage;
long itsCommands[];
};
Tools aToolBar;
... determine file ...
aToolBar.itsImage.Read("known_file.macpict");
The following code illustrates the exact usage of the CImage anImage constructor to get a valid image:
anImage.Read(...);
anImage.ReadIOStream(...);
anImage = anImage2;
anImage = imageID;
COLOR aCol = anImage.GetCLUTEntry(12);
anImage.SetPixel(CPoint(5, 5), COLOR_RED);
anImage.Write();If you read or reread the image after creation, the I/O information is reset for writing.
anImage2.WriteIOStream();
You can also write images to an alternate format. For example:
anImage.Write("file.bmp");
anImage2.WriteIOStream(anIOStream);
If you try to write an image either without reading it or without specifying an output name or stream, the process fails and returns an error. For example:
CImage anImage(aPixmap);
BOOLEAN isOk = anImage.Write();
// error! does not know what
// to write! Returns FALSE
BOOLEAN isOk = anImage.Write("file.bmp");
// OK
|
|
|
DEFAULT
| BMP; use on all platforms |
MACPICT
| Macintosh PICT; use only on the Macintosh |
|
|
|
|
XVT_IMAGE
|
itsImageId;
| The image ID |
CImageIO
|
*itsIO;
| The image's I/O implementation |
CImage();
CImage(XVT_IMAGE_FORMAT theFormat, short theWidth, short theHeight);
CImage object of specified format (theFormat), width (theWidth), and height (theHeight).
CImage(const CStringRW &theFileName);
theFileName. The file can be an xbm, xpm, BMP, or Macintosh PICT.
CImage(XVT_IOSTREAM theIOStream);
theIOStream. Keep in mind that the created image references the I/O stream, and you are responsible for maintaining the integrity of that stream.
CImage(XVT_IMAGE theImageId);
XVT_IMAGE object is not modified.
CImage(int theResId);
theResId.
CImage(XVT_PIXMAP thePixmap);
XVT_PIXMAP object.
CImage(const CImage &theImage);
theImage.
CImage & operator= (const CImage &theImage);
theImage.
~CImage();
operator XVT_IMAGE (void) const;
CImage object, this operator gets an XVT Portability Toolkit XVT_IMAGE object. This operator is used with XVT Portability Toolkit image functions. Since this method returns a direct reference into internal information, use this method carefully. Specifically, do not use this method in cases in which the calling method might destroy or alter the handle.
CImage& operator= (XVT_IMAGE theImageId);
BOOLEAN Read(const CStringRW &theFile);
XVT_IOSTREAM, or, on the Macintosh only, as a Macintosh PICT.
BOOLEAN ReadIOStream(XVT_IOSTREAM theIOStream);
BOOLEAN Write(
const CStringRW &theFile = NULLString,
PWR_IMAGE_FILETYPE theType = DEFAULT);
FALSE.
BOOLEAN WriteIOStream(
XVT_IOSTREAM theIOStream = NULL,
PWR_IMAGE_FILETYPE theType = DEFAULT);
FALSE.
void FillRect(COLOR theColor, const CRect &theFrame);
theColor. If there is no color in the image that matches the fill color exactly, the nearest color is used. If any portion of theFrame lies outside the boundary of the image, the portion(s) will be clipped.
void Transfer(const CRect &theDestFrame,
const CImage &theSourceImage,
const CRect &theSourceFrame);
void TransferPixmap(const CRect &theDestFrame,
XVT_PIXMAP thePixmap,
const CRect &theSourceFrame);
theSourceFrame and theDestFrame are not congruent, this function translates and scales the source region as necessary to fit it into the destination rectangle. Any parts of the source or destination rectangles that fall outside of the bounds of their respective containers are ignored.
void SetPixel(const CPoint &theLoc, COLOR theColor);
theLoc is the location of the pixel relative to 0,0. This method handles the arithmetic for the array addressing and converting colors to different color formats.
COLOR GetPixel(const CPoint &theLoc) const;
theLoc is the location of the pixel relative to 0,0. This method handles the arithmetic for the array addressing and converting colors to different color formats.
XVT_IMAGE_FORMAT GetFormat(void) const;
void GetDimensions(short *theWidth,
short *theHeight) const;
theWidth and theHeight.
short GetWidth(void) const;
short GetHeight(void) const;
theHeight.
COLOR GetCLUTEntry(short theIndex) const;
theIndex is the color entry to retrieve. This method is useful only for images with an XVT Portability Toolkit color format of XVT_IMAGE_CL8, since the other formats do not have look-up tables.
short GetNumColors(void) const;
XVT_IMAGE_CL8, since the other formats do not have look-up tables.
void GetResolution(long *theHRes, long *theVRes) const;
long GetHRes(void) const;
long GetVRes(void) const;
void SetCLUTEntry(short theIndex, COLOR theColor);
theIndex must be between 0 and 255 (inclusive). This method does not alter the number of colors used by the image, nor does it alter the image itself. The method is useful only with images with the XVT Portability Toolkit color format XVT_IMAGE_CL8, since the other formats do not have look-up tables.
void SetNumColors(short theNum);
XVT_IMAGE_CL8, since the other formats do not have look-up tables.
void SetResolution(long theHRes, long theVRes);
void SetHRes(long theHRes);
void SetVRes(long theVRes);