You can use Imaging library directly from your Object Pascal
project by means of
This kind of usage is recommended but you can also use Imaging library
in the form of external library - dynamic link library (Windows
dll file) or shared objects (Linux
Using external library can be useful if you have have more executables
using Imaging which will be distributed together (so you can have
smaller executables). This is also only way how to use Imaging from
programming languages other than Object Pascal.
First you need Imaging compiled to external library. Projects
for building external library can be found in
You can also use build scripts named
BuildLibrary*.sh. They are located in
Scripts directory and compiled library will be placed
Bin directory. In order to successfully use
these scripts you must have paths to compilers properly set.
When you have compiled library you must assure that operating system is
be able to find it at your application's startup.
Windows library is named
Linux version has name
Next thing you need is wrapper for programming language you want to use.
Now there are wrappers for Object Pascal, C/C++
and Delphi.NET. Wrappers are located in
stringtypes are changed to
PChartypes, dynamic arrays are not used at all - wrapper type is used instead. Also all function names have
Here you can find some code fragments which will show you how to use dll/so access to Imaging library. If you want samples in language other than Object Pascal look at.
uses ImagingTypes, ImagingImport; var Img: begin // this call loads external Imaging library, you should check if it was successful if not then WriteLn('Imaging library dll was not loaded successfully, program will crash soon!'); // call this before any access to TImageData is made (Img); // load some image ('/home/galfar/images/jaguar.jpg', Img); // compress it to DXT1 format (Img, ifDXT1); // and save it in DDS file format ('/home/galfar/images/jaguar.dds', Img); // free memory occupied by image (Img); // unload Imaging library ; end.
Since is Object Pascal dynamic array, which can not be used from other languages, all parameters of this type are replaced with typed parameters. Some new functions are introduced for accessing list's items and properties. You can see them all in action in the next code listing.
uses ImagingTypes, ImagingImport; var ImgList: ; Img: ; I, Size: LongInt; begin // this call loads external Imaging library, you should check if it was successful if not then WriteLn('Imaging library dll was not loaded successfully, program will crash soon!'); // make sure list pointer doesn't point to invalid memory address ImgList := nil; // load some images, list's size is changed during loading ('/home/galfar/images/jaguar_with_mipmaps.jpg', Img); // get the actual list's size Size := (ImgList); for I := 0 to Size - 1 do begin // get list's element (ImgList, Img, I); // resize element (Img, Img.Width / 2, Img.Height / 2, rfBicubic); // set list's element (ImgList, Img, I); end; // create space for new image in the list (ImgList, Size + 1); // create new image (256, 256, ifDXT1, Img); // put this new image into the list (ImgList, Img, Size); // save halved images to file ('/home/galfar/images/jaguar_smaller.dds', Img); // free all images in list and list itself (ImgList); // unload Imaging library ; end.