unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls,jpeg, StdCtrls;
type
TForm1 = class(TForm)
Button2: TButton;
ScrollBox1: TScrollBox;
Image1: TImage;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
ScrollBox2: TScrollBox;
StaticText1: TStaticText;
Image2: TImage;
ComboBox1: TComboBox;
StaticText2: TStaticText;
Button3: TButton;
StaticText3: TStaticText;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ComboBox1Enter(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
compqui:integer;
bmp:tbitmap;
jpg:tjpegimage;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
bmp:=tbitmap.Create;
jpg:=tjpegimage.Create;
if opendialog1.Execute then
begin
image1.Picture.LoadFromFile(opendialog1.FileName);
bmp:=image1.Picture.Bitmap;
jpg.CompressionQuality:=100;
jpg.Compress;
jpg.Assign(bmp);
jpg.SaveToFile('c:/a.jpg');
image2.Picture.LoadFromFile('c:/a.jpg');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
bmp:=tbitmap.Create;
jpg:=tjpegimage.Create;
bmp:=image1.Picture.Bitmap;
jpg.CompressionQuality:=compqui;
jpg.Compress;
jpg.Assign(bmp);
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
compqui:=strtoint(combobox1.Text);
if compqui>100 then
begin
compqui:=100;
combobox1.Text:=inttostr(100);
end;
jpg.CompressionQuality:=compqui;
jpg.Compress;
jpg.Assign(bmp);
jpg.SaveToFile('c:/a.jpg');
image2.Picture.LoadFromFile('c:/a.jpg');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if opendialog1.FileName='' then
exit;
showmessage('请加上完整的文件名,包括扩展名');
if savedialog1.Execute then
begin
jpg.SaveToFile(savedialog1.FileName);
deletefile('c:/a.jpg');
end;
end;
procedure TForm1.ComboBox1Enter(Sender: TObject);
begin
compqui:=strtoint(combobox1.Text);
if compqui>100 then
begin
compqui:=100;
combobox1.Text:=inttostr(100);
end;
end;
end.
///
刚学 delphi 时做的