Technical Information Database TI4528D.txt - Converting a BMP to a JPEG and vice-versa under Delphi 3 Category :Delphi 3.x Platform :All-32Bit Product :Delphi3.x, Description: Q: How do I convert a BMP to a JPEG and vice versa? A: This little project demonstrates how to do it using the JPEG components that ship with Delphi 3 (in the INFO\EXTRAS\JPEG directory). Just start a brand new project in Delphi 3. Drop two TButtons on the form. Then double click on the first button. Then double click on the second button. (This hooks the event handlers up). Finally, replace the code inbetween "{$R *.DFM}" and "end." in Unit1 with this code: uses JPEG; procedure TForm1.Button1Click(Sender: TObject); var MyJPEG : TJPEGImage; MyBMP : TBitmap; begin { Convert a BMP to a JPEG } MyBMP := TBitmap.Create; with MyBMP do try LoadFromFile('YourBmpHere.BMP'); MyJPEG := TJPEGImage.Create; with MyJPEG do begin Assign(MyBMP); SaveToFile('YourJpegHere.JPEG'); Free; end; finally Free; end; end; procedure TForm1.Button2Click(Sender: TObject); var MyJPEG : TJPEGImage; MyBMP : TBitmap; begin { Convert a JPEG to a BMP } MyJPEG := TJPEGImage.Create; with MyJPEG do begin LoadFromFile('YourJpegHere.JPEG'); MyBMP := TBitmap.Create; with MyBMP do begin Width := MyJPEG.Width; Height := MyJPEG.Height; Canvas.Draw(0,0,MyJPEG); SaveToFile('YourBmpHere.BMP'); Free; end; Free; end; end; Reference: None 3/31/99 1:08:27 PM
Last Modified: 01-SEP-99