test1.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. unit test1;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5. StdCtrls, jpeg, ExtCtrls, FileCtrl, ComCtrls;
  6. type
  7. TForm1 = class(TForm)
  8. Image1: TImage;
  9. Panel1: TPanel;
  10. DirectoryListBox1: TDirectoryListBox;
  11. FileListBox1: TFileListBox;
  12. Panel3: TPanel;
  13. DriveComboBox1: TDriveComboBox;
  14. Scale: TComboBox;
  15. PixelFormat: TComboBox;
  16. ColorSpace: TComboBox;
  17. Performance: TComboBox;
  18. ProgressiveDisplay: TCheckBox;
  19. IncrementalDisplay: TCheckBox;
  20. procedure FileListBox1DblClick(Sender: TObject);
  21. procedure SetJPEGOptions(Sender: TObject);
  22. procedure FormCreate(Sender: TObject);
  23. procedure ProgressUpdate(Sender: TObject; Stage: TProgressStage;
  24. PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
  25. private
  26. { Private declarations }
  27. public
  28. { Public declarations }
  29. end;
  30. var
  31. Form1: TForm1;
  32. implementation
  33. {$R *.DFM}
  34. procedure TForm1.FileListBox1DblClick(Sender: TObject);
  35. begin
  36. try
  37. Image1.Picture.LoadFromFile(FileListbox1.Filename);
  38. except
  39. on EInvalidGraphic do
  40. Image1.Picture.Graphic := nil;
  41. end;
  42. SetJPEGOptions(self);
  43. end;
  44. procedure TForm1.SetJPEGOptions(Sender: TObject);
  45. var
  46. Temp: Boolean;
  47. begin
  48. Temp := Image1.Picture.Graphic is TJPEGImage;
  49. if Temp then
  50. with TJPEGImage(Image1.Picture.Graphic) do
  51. begin
  52. PixelFormat := TJPEGPixelFormat(Self.PixelFormat.ItemIndex);
  53. Scale := TJPEGScale(Self.Scale.ItemIndex);
  54. Grayscale := Boolean(Colorspace.ItemIndex);
  55. Performance := TJPEGPerformance(Self.Performance.ItemIndex);
  56. ProgressiveDisplay := Self.ProgressiveDisplay.Checked;
  57. end;
  58. Scale.Enabled := Temp;
  59. PixelFormat.Enabled := Temp;
  60. Colorspace.Enabled := Temp;
  61. Performance.Enabled := Temp;
  62. ProgressiveDisplay.Enabled := Temp
  63. and TJPEGImage(Image1.Picture.Graphic).ProgressiveEncoding;
  64. Image1.IncrementalDisplay := IncrementalDisplay.Checked;
  65. end;
  66. procedure TForm1.FormCreate(Sender: TObject);
  67. begin
  68. Scale.ItemIndex := 0;
  69. PixelFormat.ItemIndex := 0;
  70. Colorspace.ItemIndex := 0;
  71. Performance.ItemIndex := 0;
  72. FileListbox1.Mask := '*.jpg;*.bmp;*.wmf;*.emf;*.ico';
  73. Image1.OnProgress := ProgressUpdate;
  74. end;
  75. procedure TForm1.ProgressUpdate(Sender: TObject; Stage: TProgressStage;
  76. PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
  77. begin
  78. if Stage = psRunning then
  79. Caption := Format('%d%%',[PercentDone])
  80. else
  81. Caption := 'Form1';
  82. end;
  83. end.