home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / INFO / EXTRAS / JPEG / TEST / TEST1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-12-20  |  2.5 KB  |  97 lines

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