Mega Code Archive

 
Categories / Delphi / Graphic
 

Convert bmp file to jpeg file

Title: Convert bmp-file to jpeg-file Button1Click procedure creates variable of TBitmap type and loads a picture stored in a file. Button2Click procedure creates variable of TJPEGImage type and assignes bitmap object to this variable. uses JPEG; ... var Bitmap: TBitmap; ... procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then begin Bitmap:=TBitmap.Create; Bitmap.LoadFromFile(OpenDialog1.FileName); Image1.Picture.LoadFromFile(OpenDialog1.FileName); end; end; procedure TForm1.Button2Click(Sender: TObject); var JPEGImage: TJPEGImage; begin try JPEGImage:=TJPEGImage.Create; JPEGImage.CompressionQuality:=80; JPEGImage.Assign(Bitmap); if SaveDialog1.Execute then JPEGImage.SaveToFile(SaveDialog1.FileName); Label1.Caption:='Convertation finished'; finally Bitmap.Free; JPEGImage.Free; end; end;