MainUnit.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. {$include GR32.inc}
  36. uses
  37. {$IFNDEF FPC} Windows, {$ELSE} LCLIntf, LCLType, 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. {$R *.dfm}
  62. uses
  63. {$IFDEF Darwin}
  64. MacOSAll,
  65. {$ENDIF}
  66. GR32.ImageFormats.JPG;
  67. procedure TFormImage32Example.FormCreate(Sender: TObject);
  68. begin
  69. Image.Bitmap.LoadFromResourceName(HInstance, 'Delphi', RT_RCDATA);
  70. with TKernelResampler.Create(Image.Bitmap) do
  71. begin
  72. KernelMode := kmTableNearest;
  73. TableSize := 16;
  74. end;
  75. end;
  76. procedure TFormImage32Example.RgpBitmapAlignClick(Sender: TObject);
  77. const
  78. BA_CONSTS: array [0..2] of TBitmapAlign = (baTopLeft, baCenter, baTile);
  79. begin
  80. Image.BitmapAlign := BA_CONSTS[RgpBitmapAlign.ItemIndex];
  81. end;
  82. procedure TFormImage32Example.SbrScaleChange(Sender: TObject);
  83. begin
  84. SbrScale.Update;
  85. Image.Scale := SbrScale.Position * 0.01;
  86. end;
  87. procedure TFormImage32Example.RgpScaleModeClick(Sender: TObject);
  88. const
  89. SM_CONSTS: array [0..5] of TScaleMode = (smNormal, smStretch, smScale, smResize, smOptimal, smOptimalScaled);
  90. begin
  91. Image.ScaleMode := SM_CONSTS[RgpScaleMode.ItemIndex];
  92. SbrScale.Enabled := (Image.ScaleMode in [smScale, smOptimalScaled]);
  93. end;
  94. procedure TFormImage32Example.RgpKernelClick(Sender: TObject);
  95. const
  96. K_CONSTS: array [0..4] of TCustomKernelClass =
  97. (TBoxKernel, TLinearKernel, TSplineKernel, TLanczosKernel, TMitchellKernel);
  98. begin
  99. TKernelResampler(Image.Bitmap.Resampler).Kernel := K_CONSTS[RgpKernel.ItemIndex].Create;
  100. end;
  101. end.