Manipulating ImagesManipulating ImagesImaging offers some image manipulation functions which work
with all supported image data formats. Conversions, resizing,
color reduction and other are available.
You can find list of all low level image manipulation and drawing/pixel
functions in Low Level Interface section.
You can look at usage of many of these functions in the
VampConvert
and
Benchmark Object Pascal demos
and C++ Benchmark demo.In the following code listing you can see typical usage of Imaging's
manipulation functions.
uses
ImagingTypes, Imaging;
var
Img, ImgClone: TImageData;
begin
...
// image is now initialized and loaded
// now we want image to be mirrored
MirrorImage(Img);
// and flipped
FlipImage(Img);
// conversion to 32bit ARGB format
ConvertImage(Img, ifA8R8G8B8);
// swap alpha channel with green channel
SwapChannels(Img, ChannelAlpha, ChannelGreen);
// now we make clone of image
InitImage(ImgClone);
CloneImage(Img, ImgClone);
// reduce colors of clone to 1024
ReduceColors(ImgClone, 1024);
// and resize original image
ResizeImage(Img, Img.Width * 2, Image.Height div 2, rfBicubic);
// finally convert clone to DXT5
ConvertImage(ImgClone, ifDXT5);
// do something else with image
...
end.
In this example you can find how to pass fill color parameters to
functions like FillRect. These functions work for all possible image
data format so fill color is defined as pointer to pixel in image's format.
You can also use GetPixel32, SetPixel32,
GetPixelFP, and SetPixelFP to set/get pixel colors
which are automatically converted to native color format of each data format.
var
Img: TImageData;
Pix32: TColor32Rec
Pix24: TColor24Rec
Pix64: TColor64Rec
Pix48: TColor48Rec
PixWord: Word;
PixByte: Byte;
begin
...
// image is now initialized and loaded
// now we set pixel colors
Pix32.Color := $FFFF0000; // opaque red
Pix64.Color := $FFFF0000FFFF0000; // opaque green
with Pix24 do begin R := $FF; G := $FF; B := 0; end; // yellow
with Pix48 do begin R := $FF00; G := $00FF; B := $0800; end; // something redish
PixWord := (31 shl 10) or (15 shl 5) or 25; // something violetish in R5G5B5
PixByte := 111;
// image is then converted between various formats
// and rectangle is filled with appropriate pixels
ConvertImage(Img, ifA16R16G16B16);
FillRect(Img, 20, 20, 60, 40, @Pix64);
ConvertImage(Img, ifA8R8G8B8);
FillRect(Img, 20, 20, 60, 40, @Pix32);
ConvertImage(Img, ifR16G16B16);
FillRect(Img, 20, 20, 60, 40, @Pix48);
ConvertImage(Img, ifR8G8B8);
FillRect(Img, 20, 20, 60, 40, @Pix24);
ConvertImage(Img, ifX1R5G5B5);
FillRect(Img, 20, 20, 60, 40, @PixWord);
ConvertImage(Img, ifGray8);
FillRect(Img, 20, 20, 60, 40, @PixByte);
...
end.