Metafile Sizes and Rendering
As you'll recall from Chapter 11, the Image class has several properties that describe the image. Because Metafile is descended from Image, these properties also apply to metafiles. In particular, you'll find the following properties useful when working with metafiles:
U MarihutByRelQtiject
|
Image Properties (selection) | ||
|
Type |
Property |
Accessibility |
|
Size |
Size |
get |
|
int |
Width |
get |
|
int |
Height |
get |
|
float |
HorizontalResolution |
get |
|
float |
VerticalResolution |
get |
|
SizeF |
PhysicalDimension |
get |
For Bitmap objects, the Size, Width, and Height properties indicate the pixel dimension of the bitmap—the number of rows and columns of bits. The HorizontalResolution and VerticalResolution properties report information that's probably encoded in the bitmap: the number of pixels per inch horizontally and vertically. You can easily calculate a metrical size of the bitmap in inches by dividing the Width by the HorizontalResolution and the Height by the VerticalResolution. If you convert those dimensions to millimeters and multiply by 100, you'll get numbers equal to the PhysicalDimension property, which is the size of the bitmap in units of hundredths of millimeters.
For Metafile objects, the Size, Width, and Height properties are a little different. In many cases, these properties reflect the extents of the coordinates and sizes of all the objects in the metafile. For example, if the metafile consisted of a single DrawLine call with endpoint coordinates of (-50, 25) and (100, 250), the Width would probably be 150 (or thereabouts) and the Height would be 225 (or so). However, as we'll see shortly, the creator of the metafile can set the Width and Height properties to something different. Also, wide lines could affect the size of the image and hence the Width and Height properties. So, even though metafiles don't have pixels, they have something equivalent to a pixel size.
Metafile objects also have valid HorizontalResolution and VerticalResolution properties that indicate how the coordinates of the metafile relate to inches. That hypothetical metafile with a single DrawLine call might have HorizontalResolution and VerticalResolution values of 75, so the image would be 2 inches wide and 3 inches high. The PhysicalDimension property would be (5080, 7620).
To display a metafile in its metrical size with the upper left corner at the point (x, y), use
or one of the Drawlmage variants that uses Point or PointF arguments. The displayed size of the image is not affected by the page transform but is affected by the world transform.
The following Drawlmage method—and its variants using Rectangle and RectangleF arguments— displays a metafile stretched to the rectangle:
Both the page transform and the world transform affect the interpretation of the x, y, cx, and cy arguments. To display a metafile in its pixel size, set page units to pixels and use
The Metafile class has no additional public properties beyond what it inherits from the lmage class. However, the metafile itself has a header that provides additional information about the metafile. The metafile header is encapsulated in the MetafileHeader class. You can obtain an object of MetafileHeader using the following instance method:
Post a comment