WIC Transformations

Again, there is very little you have to do to use TIFF support... just open a file in the Image component. However, it is important to notice that there are two sides to the WIC. One is loading and saving files with given formats. The second side is the ability to process the images. To accomplish this you have to access to the iwicimagingFactory interface, available through the ImagingFactory property of the TWICImage class. This COM factory lets you create specific COM objects that expose given interfaces:

  • the IWICFormatConverter interface to converter formats
  • the IWICBitmapScaler interfaces for the scaling bitmap
  • the IWICBitmapCl ipper interfaces for bitmap clipping support
  • the IWICBitmapFl i pRotator interfaces to flip and rotate images
  • the IWICColorTransform and IWICColorContext interfaces that can be used for color management

Again, there is a plethora of methods and options, much more than I can cover in this section. What I'll do, instead, is to show you a practical example of how a Delphi application can manipulate images. The first part of the code extracts information from the image currently loaded in the TWICImage object, using the IWICBitmap interface: var wicImg: TWICImage; iBmpSource: IWICBitmapSource; puiWidth, puiHeight: UINT; begin if Imagel.Picture.Graphic is TWICImage then begin wicImg := TWICImage (Imagel.Picture.Graphic); iBmpSource := wicImg.Handle as IWICBitmapSource; iBmpSource.GetPixelFormat(pPixelFormat); iBmpSource.GetSize(puiWidth, puiHeight); Log ( 'Original: ' + IntToStr (puiWidth) + '/' + IntToStr (puiHeight));

This outputs the width and and height of the bitmap. The second step is to extract the flip/rotator interface, assign it to the source bitmap, ask for a given operation (in this case a 90 degree rotation), and again display the width and height of the rotated image: var iFlipRot: IWICBitmapFlipRotator; iBmpSource: IWICBitmapSource; puiWidth2, puiHeight2: UINT; begin wicImg.ImagingFactory.CreateBitmapFlipRotator(iFlipRot); iFlipRot.Initialize (iBmpSource, WICBitmapTransformRotate90); iFlipRot.GetSize(puiWidth2, puiHeight2); Log ( 'Rotated: ' + IntToStr (puiWidth2) + '/' + IntToStr (puiHeight2));

Finally we have to extract the rotated bitmap (passing the correct dimensions for the rectangle of the source image) and assign it as the source of the TWICImage object: var wicBitmap: IWICBitmap; begin wicImg.ImagingFactory.CreateBitmapFromSourceRect(

iFlipRot, 0, 0, puiWidth2, puiHeight2, wicBitmap); if Assigned (wicBitmap) then wicImg.Handle := wicBitmap; Imagel.Repaint;

You can see a sample result in the image below. Consider that you can do similar transformation for each file format, but need to load them in the TWICImage object first. In this case I've loaded and rotated a sample TIF image (the test page of a FAX), which is included along with the source code of the example:

Was this article helpful?

0 0

Post a comment