Bitmaps and Metafiles
This section provides information about working with bitmaps and metafiles in the Windows Graphics Device Interface (GDI). Understanding these concepts is crucial for displaying and manipulating graphical data within your Windows applications.
Bitmaps
A bitmap is a graphics image represented as a grid of pixels. Each pixel has a specific color value. GDI provides functions to create, load, save, and manipulate bitmaps. Common operations include drawing bitmaps to the screen, scaling, stretching, and manipulating their pixel data.
Key Concepts:
- BITMAP structure: Defines the dimensions, color format, and memory location of a bitmap.
- Device-Dependent Bitmap (DDB): A bitmap that is optimized for the display device on which it was created.
- Device-Independent Bitmap (DIB): A bitmap that can be displayed on any device, regardless of its specific characteristics.
Commonly Used Functions:
CreateBitmap,CreateBitmapIndirect: Creates a new bitmap.LoadBitmap: Loads a bitmap resource from an executable file or module.BitBlt: Copies a block of pixels from a source device context to a destination device context.StretchBlt: Copies a block of pixels from a source device context to a destination device context, stretching or compressing it to fit the destination dimensions.GetDIBits,SetDIBits: Accesses and modifies the pixel data of a DIB.
Metafiles
A metafile is a sequence of GDI drawing commands that can be stored and replayed. Unlike bitmaps, which are raster images, metafiles are vector-based. This means they describe graphics in terms of geometric primitives (lines, curves, shapes) and attributes (color, thickness). Metafiles offer scalability without loss of quality and can be edited more easily than bitmaps.
Key Concepts:
- Enhanced Metafile (EMF): A 32-bit metafile format that is more powerful and flexible than the older WMF format.
- Windows Metafile (WMF): An older, 16-bit metafile format.
- Metafile Records: Individual drawing commands stored within a metafile.
Commonly Used Functions:
CreateEnhMetaFile,CreateMetaFile: Creates a new metafile device context.EnumEnhMetaFile: Enumerates the records in an enhanced metafile.PlayEnhMetaFile,PlayMetaFile: Plays back the GDI commands stored in a metafile to a device context.GdipCreateBitmapFromGraphics(GDI+): While GDI+ is a separate API, it can interact with GDI objects and often uses concepts similar to bitmaps and metafiles for richer graphics.
Choosing Between Bitmaps and Metafiles
The choice between using bitmaps and metafiles depends on your specific needs:
- Use Bitmaps for: Photographic images, scanned documents, complex images where vector representation is impractical, and when exact pixel-level control is required.
- Use Metafiles for: Line drawings, diagrams, logos, charts, and any graphics that need to be scaled without losing quality or require easier editing of individual elements.
Explore the linked topics for detailed information on specific functions and advanced techniques.