GDI+ Image class is a VFP class to load, save and transform BMP, JPEG, GIF, PNG and TIFF images. It provides also conversion to/from Picture object, copying to/retrieving from clipboard, capturing of screen or any window.
Description:
This
class is based on GDI+ and requires gdiplus.dll which is freely available and
can be installed on Win98 and higher. If you have not installed WinXP or .NET
runtime then you can download this DLL from
http://www.microsoft.com/downloads/release.asp?releaseid=32738
or directly:
http://download.microsoft.com/download/platformsdk/redist/3097/W98NT42KMeXP/EN-US/gdiplus_dnld.exe
gpImage.prg file contains two classes. gpInit class declares required API functions and initializes GDI+. The single instance of this class must be created before use of gpImage class and must exist all the time when GDI+ is used. Properties and methods of gpImage class are described below.
Properties:
|
ImageFormat |
format of image: "BMP", "JPEG", "TIFF" etc. (read only) |
|
PixelFormat |
pixel format of image, for example "24bppRGB" (read/write) |
|
ImageWidth |
width of image (read only) |
|
ImageHeight |
height of image (read only) |
|
HorizontalResolution |
horizontal resolution in dpi (read/write) |
|
VerticalResolution |
vertical resolution in dpi (read/write) |
Methods:
|
Create(tnWidth, tnHeight, tcPixelFormat) |
Creates an empty image object |
|
Load(tcFileName) |
Loads an image from file |
|
FromResource(tcFileName, tcBitmapName) |
Loads an image from bitmap resource in EXE/DLL file. Resource can be identified by name: img.FromResource("dxdiag.exe", "DIRECTX"), or by number: img.FromResource("shell32.dll", "#309"). |
|
FromPicture(toPicture) |
Creates an image object from Picture object |
|
GetPicture() |
Returns Picture object |
|
FromClipboard() |
Creates an image object from clipboard content |
|
ToClipboard() |
Copies an image to clipboard |
|
Thumbnail(tnWidth, tnHeight) |
Creates thumbnail of specified size |
|
SaveAsBMP(tcFileName) |
Stores image in BMP file |
|
SaveAsJPEG(tcFileName, tnQuality, tnTransform) |
Stores image in JPEG file. Optional parameter tnQuality specifies quality of JPEG compression, 0 - highest compression, 100 - highest quality, default value - 75. Optional parameter tnTransform specifies type of transformation without loss of information, any of EncoderValueTransform values. |
|
SaveAsGIF(tcFileName) |
Stores image in GIF file |
|
SaveAsTIFF(tcFileName, tnCompress, tnColorDepth) |
Stores image in TIFF file. Parameter tnCompress specifies type of compression, any of EncoderValueCompression values, optional. Parameter tnColorDepth specifies number of colors in bits per pixel (1,4,8,16,24,32,48,64), optional. |
|
SaveAsPNG(tcFileName) |
Stores image in PNG file |
|
SaveAsMultipageTIFF(tcFileName, tnCompress, tnColorDepth) |
Stores image as first page of multipage TIFF file |
|
SaveAddPage(tnImage) |
Adds specified image as page of multipage file. Parameter tnImage is a value, returned by GetImage() function of another image object. |
|
GetImage() |
Returns pointer to GDI+ image object which can be used in API functions and SaveAddPage() function. |
|
GetPixelColor(x, y) |
Returns color value of pixel |
|
GetPixelAlpha(x, y) |
Returns alpha value of pixel |
|
SetPixel(x, y, tnColor, tnAlpha) |
Sets color and alpha values of pixel |
|
Crop(x, y, tnWidth, tnHeight) |
Crops an image |
|
RotateFlip(rotateFlipType) |
Rotates and flips an image |
|
Resize(tnWidth, tnHeight, tnInterpolationMode) |
Resizes an image |
|
GetPageCount() |
Returns number of pages in multipage (TIFF) file |
|
SelectPage(tnPage) |
Selects the specified page |
|
GetFrameCount() |
Returns number of time frames in multiframe (GIF) file |
|
SelectFrame(tnFrame) |
Selects the specified time frame |
|
Capture(thWnd) |
Captures the window, specified by handle or desktop, if handle is not specified |
gpImage.h file contains definitions of ImageFormat, PixelFormat, EncoderValueTransform, rotateFlipType, InterpolationMode constants.
License:
This class is free; use it on your own risk. If you use this source code in a product, acknowledgment is not required but would be appreciated. You are not authorized to distribute or sell the class unless specific permission is given by the author.
Author:
Alexander Golovlev
Saratov, Russian Federation
avg.kedr@overta.ru, golovlev@yandex.ru
May 10, 2003