ProcComp.xml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?xml-stylesheet type="text/xsl" href="../../Xsl/doc2html.xsl"?>
  3. <doc>
  4. <title>How To ... (VCL/LCL Classes)</title>
  5. <chapter>
  6. <title>How To ... (VCL/LCL Classes)</title>
  7. <par>
  8. This section shows few possible usages of
  9. VCL/LCL Imaging Classes and related functions
  10. described in
  11. <link url="../../Usage/Components.xml">VCL/LCL Classes</link>.
  12. You can also learn how to use these classes
  13. by looking at demos which use them
  14. <link url="../../Demos/Pascal.xml">Pascal Demos</link>.
  15. </par>
  16. <par>Using <icode>TGraphic</icode> Imaging descendants:</par>
  17. <code>
  18. ...
  19. uses
  20. ImagingTypes, Imaging, ImagingClasses,
  21. // Add unit with VCL/LCL support, new file formats are automatically
  22. // registered to TPicture (so they will appear in TOpenPictureDialog for example)
  23. <ref>ImagingComponents</ref>;
  24. ...
  25. procedure Assignments;
  26. var
  27. ImgBitmap: <ref>TImagingBitmap</ref>;
  28. ImgData: <ref>TImageData</ref>;
  29. ImgClass: <ref>TBaseImage</ref>
  30. begin
  31. // Create empty Imaging bitmap
  32. ImgBitmap := <ref>TImagingBitmap</ref>.Create;
  33. // Load image from file to TImageData record and assign it to bitmap
  34. <ref>InitImage</ref>(ImgData);
  35. <ref>LoadImageFromFile</ref>('littlecat.png', ImgData);
  36. ImgBitmap.AssignFromData(ImgData);
  37. // Now create high level image class from file and assign it to bitmap
  38. // by overridden TPersistent.Assign method
  39. ImgClass := <ref>TSingleImage</ref>.CreateFromFile('notsolittlecat.png');
  40. ImgBitmap.Assign(ImgClass);
  41. // Assign Imaging bitmap to TImage component on Form1 (it should be immediately
  42. // displayed)
  43. Form1.Image.Picture.Graphic := ImgBitmap;
  44. // Free loaded images
  45. <ref>FreeImage</ref>(ImgData);
  46. ImgClass.Free;
  47. end;
  48. </code>
  49. <par>Displaying Imaging's images in VCL/LCL:</par>
  50. <code>
  51. // This procedure shows given image (high level class) on form
  52. // by converting it to TBitmap and then drawing on form's canvas
  53. procedure ShowImageOnForm1(Form: TForm; Image: <ref>TBaseImage</ref>);
  54. var
  55. Bitmap: TBitmap;
  56. begin
  57. Bitmap := TBitmap.Create;
  58. // Call Imaging procedure for converting images to Graphics' TBitmap object
  59. <ref>ConvertImageToBitmap</ref>(Image, Bitmap);
  60. // Draw bitmap onto form's canvas
  61. Form.Canvas.Draw(0, 0, Bitmap);
  62. Bitmap.Free;
  63. end;
  64. // This procedure shows given image (high level class) on form's
  65. // canvas directly without conversion so it is significantly faster
  66. // than ShowImageOnForm1. But it has a drawback: it does not work
  67. // with all image data formats.
  68. procedure ShowImageOnForm2(Form: TForm; Image: <ref>TBaseImage</ref>);
  69. begin
  70. // Call Imaging procedure for displaying images directly on canvas without
  71. // costly conversion. Drawback of this is that it supports only images in
  72. // ifA8R8G8B8 data format
  73. <ref>DisplayImage</ref>(Form.Canvas, Form.BoundsRect, Image, Image.BoundsRect);
  74. end;
  75. // You have TBitmap and you want to save it as PNG or other file format
  76. // supported by Imaging
  77. procedure SaveBitmapAsPNG(Bitmap: TBitmap; const FileName: string);
  78. var
  79. PNG: TImagingPNG;
  80. begin
  81. PNG := TImagingPNG.Create;
  82. PNG.Assign(Bitmap);
  83. PNG.SaveToFile(FileName);
  84. PNG.Free;
  85. end;
  86. </code>
  87. </chapter>
  88. </doc>