RSS订阅 | 匿名投稿
您的位置:网站首页 > 图像 > 正文

delphi Jpeg压缩的两种方法

作者:admin 来源: 日期:2014/3/8 10:32:22 人气: 标签:

方法1

procedure TForm1.Button2Click(Sender: TObject);

var

  JPEGImage: TJPEGImage;

begin

  if SavePictureDialog1.InitialDir = ' ' then

    SavePictureDialog1.InitialDir := ExtractFilePath(OpenPictureDialog1.FileName);

  if trim(LabeledEdit1.Text) <> ' ' then

    SavePictureDialog1.FileName := trim(LabeledEdit1.Text) + '.jpg ';

  if SavePictureDialog1.execute then

  begin

    JPEGImage := TJPEGImage.Create;

    JPEGImage.Assign(image1.Picture.Graphic);

    JPEGImage.CompressionQuality:=25;

    JPEGImage.Compress;

    JPEGImage.SaveToFile(ExtractFilePath(SavePictureDialog1.Filename) + trim(LabeledEdit1.Text) + '.jpg ');

  end;

end;

 

方法2

procedure Tf_NewsPic.BitBtn1Click(Sender: TObject);

var

  i: Integer;

  JI: TJPEGImage;

begin

  if not OpenPictureDialog1.Execute then exit;

  for i := 0 to OpenPictureDialog1.Files.Count - 1 do

  begin

    JI := TJPEGImage.Create;

    JI.LoadFromFile(OpenPictureDialog1.Files[i]);

    image4.Picture.Bitmap.Assign(JI);

    JI.Assign(image4.Picture.Bitmap);

    JI.CompressionQuality := 25;

    JI.Compress;

    JI.SaveToFile(zhtier.GetTempDir + ExtractFileName(OpenPictureDialog1.Files[i]));

    Q1.Append;

    TBlobField(Q1.Fieldbyname('图片')).LoadFromFile(OpenPictureDialog1.Files[i]);

    Q1.Post;

    JI.Free;

  end;

  Q1.Last;

end;


读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: