Manipulating.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?xml-stylesheet type="text/xsl" href="../../Xsl/doc2html.xsl"?>
  3. <doc>
  4. <title>Manipulating Images</title>
  5. <chapter>
  6. <title>Manipulating Images</title>
  7. <par>Imaging offers some image manipulation functions which work
  8. with all supported image data formats. Conversions, resizing,
  9. color reduction and other are available.
  10. You can find list of all low level image manipulation and drawing/pixel
  11. functions in <link url="../../Usage/LowLevel.xml">Low Level Interface</link> section.
  12. You can look at usage of many of these functions in the
  13. <link url="../../Demos/Pascal.xml#vampconvert">VampConvert</link>
  14. and
  15. <link url="../../Demos/Pascal.xml#benchmark">Benchmark</link> Object Pascal demos
  16. and <link url="../../Demos/Cpp.xml#benchmark">C++ Benchmark</link> demo.</par>
  17. <par>In the following code listing you can see typical usage of Imaging's
  18. manipulation functions.</par>
  19. <code>
  20. uses
  21. ImagingTypes, Imaging;
  22. var
  23. Img, ImgClone: <ref>TImageData</ref>;
  24. begin
  25. ...
  26. // image is now initialized and loaded
  27. // now we want image to be mirrored
  28. <ref>MirrorImage</ref>(Img);
  29. // and flipped
  30. <ref>FlipImage</ref>(Img);
  31. // conversion to 32bit ARGB format
  32. <ref>ConvertImage</ref>(Img, ifA8R8G8B8);
  33. // swap alpha channel with green channel
  34. <ref>SwapChannels</ref>(Img, ChannelAlpha, ChannelGreen);
  35. // now we make clone of image
  36. <ref>InitImage</ref>(ImgClone);
  37. <ref>CloneImage</ref>(Img, ImgClone);
  38. // reduce colors of clone to 1024
  39. <ref>ReduceColors</ref>(ImgClone, 1024);
  40. // and resize original image
  41. <ref>ResizeImage</ref>(Img, Img.Width * 2, Image.Height div 2, rfBicubic);
  42. // finally convert clone to DXT5
  43. <ref>ConvertImage</ref>(ImgClone, ifDXT5);
  44. // do something else with image
  45. ...
  46. end.
  47. </code>
  48. <par>In this example you can find how to pass fill color parameters to
  49. functions like <ref>FillRect</ref>. These functions work for all possible image
  50. data format so fill color is defined as pointer to pixel in image's format.
  51. You can also use <ref>GetPixel32</ref>, <ref>SetPixel32</ref>,
  52. <ref>GetPixelFP</ref>, and <ref>SetPixelFP</ref> to set/get pixel colors
  53. which are automatically converted to native color format of each data format.
  54. </par>
  55. <code>
  56. var
  57. Img: <ref>TImageData</ref>;
  58. Pix32: <ref>TColor32Rec</ref>
  59. Pix24: <ref>TColor24Rec</ref>
  60. Pix64: <ref>TColor64Rec</ref>
  61. Pix48: <ref>TColor48Rec</ref>
  62. PixWord: Word;
  63. PixByte: Byte;
  64. begin
  65. ...
  66. // image is now initialized and loaded
  67. // now we set pixel colors
  68. Pix32.Color := $FFFF0000; // opaque red
  69. Pix64.Color := $FFFF0000FFFF0000; // opaque green
  70. with Pix24 do begin R := $FF; G := $FF; B := 0; end; // yellow
  71. with Pix48 do begin R := $FF00; G := $00FF; B := $0800; end; // something redish
  72. PixWord := (31 shl 10) or (15 shl 5) or 25; // something violetish in R5G5B5
  73. PixByte := 111;
  74. // image is then converted between various formats
  75. // and rectangle is filled with appropriate pixels
  76. <ref>ConvertImage</ref>(Img, ifA16R16G16B16);
  77. <ref>FillRect</ref>(Img, 20, 20, 60, 40, @Pix64);
  78. ConvertImage(Img, ifA8R8G8B8);
  79. FillRect(Img, 20, 20, 60, 40, @Pix32);
  80. ConvertImage(Img, ifR16G16B16);
  81. FillRect(Img, 20, 20, 60, 40, @Pix48);
  82. ConvertImage(Img, ifR8G8B8);
  83. FillRect(Img, 20, 20, 60, 40, @Pix24);
  84. ConvertImage(Img, ifX1R5G5B5);
  85. FillRect(Img, 20, 20, 60, 40, @PixWord);
  86. ConvertImage(Img, ifGray8);
  87. FillRect(Img, 20, 20, 60, 40, @PixByte);
  88. ...
  89. end.
  90. </code>
  91. </chapter>
  92. </doc>