- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


TI3332 - Converting a BMP to a JPEG and Vice Versa



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;




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile