MainUnit.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. unit MainUnit;
  2. (* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1 or LGPL 2.1 with linking exception
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * Alternatively, the contents of this file may be used under the terms of the
  16. * Free Pascal modified version of the GNU Lesser General Public License
  17. * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
  18. * of this license are applicable instead of those above.
  19. * Please see the file LICENSE.txt for additional information concerning this
  20. * license.
  21. *
  22. * The Original Code is Graphics32
  23. *
  24. * The Initial Developer of the Original Code is
  25. * Alex A. Denisov
  26. *
  27. * Portions created by the Initial Developer are Copyright (C) 2000-2005
  28. * the Initial Developer. All Rights Reserved.
  29. *
  30. * Contributor(s):
  31. * Andre Beckedorf <[email protected]>
  32. *
  33. * ***** END LICENSE BLOCK ***** *)
  34. interface
  35. {$I GR32.inc}
  36. uses
  37. {$IFNDEF FPC} Windows, {$ELSE} LCLIntf, LResources, {$ENDIF}
  38. SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
  39. GR32, GR32_Image, GR32_Resamplers, GR32_RangeBars;
  40. type
  41. TFormImage32Example = class(TForm)
  42. Image: TImage32;
  43. PnlImage: TPanel;
  44. PnlControl: TPanel;
  45. RgpScaleMode: TRadioGroup;
  46. RgpKernel: TRadioGroup;
  47. RgpBitmapAlign: TRadioGroup;
  48. LblScale: TStaticText;
  49. SbrScale: TGaugeBar;
  50. procedure FormCreate(Sender: TObject);
  51. procedure RgpBitmapAlignClick(Sender: TObject);
  52. procedure SbrScaleChange(Sender: TObject);
  53. procedure RgpScaleModeClick(Sender: TObject);
  54. procedure RgpKernelClick(Sender: TObject);
  55. public
  56. Time: Single;
  57. end;
  58. var
  59. FormImage32Example: TFormImage32Example;
  60. implementation
  61. {$IFDEF FPC}
  62. {$R *.lfm}
  63. {$ELSE}
  64. {$R *.dfm}
  65. {$ENDIF}
  66. uses
  67. {$IFDEF Darwin}
  68. MacOSAll,
  69. {$ENDIF}
  70. {$IFNDEF FPC}
  71. JPEG;
  72. {$ELSE}
  73. LazJPG;
  74. {$ENDIF}
  75. procedure TFormImage32Example.FormCreate(Sender: TObject);
  76. var
  77. ResStream: TResourceStream;
  78. JPEG: TJPEGImage;
  79. begin
  80. JPEG := TJPEGImage.Create;
  81. try
  82. ResStream := TResourceStream.Create(HInstance, 'Delphi', RT_RCDATA);
  83. try
  84. JPEG.LoadFromStream(ResStream);
  85. finally
  86. ResStream.Free;
  87. end;
  88. Image.Bitmap.Assign(JPEG);
  89. finally
  90. JPEG.Free;
  91. end;
  92. with TKernelResampler.Create(Image.Bitmap) do
  93. begin
  94. KernelMode := kmTableNearest;
  95. TableSize := 16;
  96. end;
  97. end;
  98. procedure TFormImage32Example.RgpBitmapAlignClick(Sender: TObject);
  99. const
  100. BA_CONSTS: array [0..2] of TBitmapAlign = (baTopLeft, baCenter, baTile);
  101. begin
  102. Image.BitmapAlign := BA_CONSTS[RgpBitmapAlign.ItemIndex];
  103. end;
  104. procedure TFormImage32Example.SbrScaleChange(Sender: TObject);
  105. begin
  106. SbrScale.Update;
  107. Image.Scale := SbrScale.Position * 0.01;
  108. end;
  109. procedure TFormImage32Example.RgpScaleModeClick(Sender: TObject);
  110. const
  111. SM_CONSTS: array [0..5] of TScaleMode = (smNormal, smStretch, smScale, smResize, smOptimal, smOptimalScaled);
  112. var
  113. ScaleEnabled: Boolean;
  114. begin
  115. Image.ScaleMode := SM_CONSTS[RgpScaleMode.ItemIndex];
  116. ScaleEnabled := (RgpScaleMode.ItemIndex = 2) or (RgpScaleMode.ItemIndex = 5);
  117. SbrScale.Enabled := ScaleEnabled;
  118. SbrScale.Enabled := ScaleEnabled;
  119. end;
  120. procedure TFormImage32Example.RgpKernelClick(Sender: TObject);
  121. const
  122. K_CONSTS: array [0..4] of TCustomKernelClass =
  123. (TBoxKernel, TLinearKernel, TSplineKernel, TLanczosKernel, TMitchellKernel);
  124. begin
  125. TKernelResampler(Image.Bitmap.Resampler).Kernel := K_CONSTS[RgpKernel.ItemIndex].Create;
  126. end;
  127. end.