Usually when dealing with bitmaps you're using "Graphics.pas".
madExcept doesn't use that, because that would mean linking all the
VCL stuff in. Furthermore "Graphics" doesn't support all the features which
madExcept needs. So I've decided to create a whole new unit which
implements exactly that part of functionality which I need for
madExcept without using any VCL units. The resulting unit is named
"madNVBitmap" ("NV" stands for "non VCL"). For a list of what's contained
in this unit please look at the madNVBitmap Reference.
All the functionality is available through the "INVBitmap" interface. There
are two ways to get an instance of this interface: You can either load a
bitmap from harddisk, or you can ask madNVBitmap to capture the current
screen content. Both "LoadBitmap" and "ScreenShot" return "nil", if they
fail.
 |
type
INVBitmap = interface ['{3EE757B5-CC56-4610-A917-E8731737D5BE}'];
function LoadBitmap (bmpFile: string) : INVBitmap;
function ScreenShot (thisAppOnly: boolean = false) : INVBitmap;
|
|
Once you have a valid INVBitmap instance, you can ask the width and
height of the encapsulated bitmap. The color depth is always "true color".
 |
property INVBitmap. Width : integer;
property INVBitmap. Height : integer;
|
|
What is the main purpose of a bitmap? Of course to show/draw it somewhere:
 |
function INVBitmap. Draw (dc: dword; x, y: integer) : boolean;
|
|
One nice functionality offered by madNVBitmap is smooth scaling of the
bitmap. The scaling uses the high quality "Mitchell" filter. Resizing is
always done in a way that doesn't change the aspect ratio of the original
bitmap. E.g. if you call "Zoom(32, 32)" on a 800x600 bitmap, then the
resulting bitmap will have a size of 32x24. Calling "Zoom" does not change
the current bitmap, instead is creates and returns a new INVBitmap
instance for the resized bitmap.
 |
function INVBitmap. Zoom (width, height: integer) : INVBitmap;
|
|
Finally we can save our bitmap in either "bmp" or "png" format. When saving
in "png" format you can choose between some compression modes. Generally
you can either save in 16 gray shades or in 256 colors, or you can let
madNVBitmap decide for itself which mode to use, depending on how big the
resulting "png" file would get in either mode.
 |
type
TPngFormat = (pf256Colors, pf16Grays, pf50kb, pf100kb, pf200kb, pf300kb);
function INVBitmap. AsBmpStr : string;
function INVBitmap. AsPngStr (format: TPngFormat = pf256Colors) : string;
function INVBitmap. SaveBmp (bmpFile: UnicodeString ) : boolean;
function INVBitmap. SavePng (pngFile: UnicodeString; format: TPngFormat = pf256Colors) : boolean;
ScreenShot.SavePng('C:\ScreenShot.png');
|
|