Convert Between BMP and JPG With Delphi

Need to convert BMP to JPG or JPG to BMP with Delphi?
Don’t worry, this should help you out!😉

// convert bmp to jpg

uses jpeg;

procedure TForm1.Button1Click(Sender: TObject);
var
bmp : TImage;
jpg : TJpegImage;
begin
bmp := TImage.Create(nil);
jpg := TJpegImage.Create;
bmp.picture.bitmap.LoadFromFile ( ‘c:\gambar.bmp’ );
jpg.Assign( bmp.picture.bitmap );
jpg.SaveToFile ( ‘c:\gambar.jpg’ );
jpg.Free;
bmp.Free;
end;

//convert jpg to bmp

uses
JPEG;

procedure JPEGtoBMP(const FileName: TFileName);
var
jpeg: TJPEGImage;
bmp: TBitmap;
begin
jpeg := TJPEGImage.Create;
try
jpeg.CompressionQuality := 100; {Default Value}
jpeg.LoadFromFile(FileName);
bmp := TBitmap.Create;
try
bmp.Assign(jpeg);
bmp.SaveTofile(ChangeFileExt(FileName, ‘.bmp’));
finally
bmp.Free
end;
finally
jpeg.Free
end;
end;

One Response to Convert Between BMP and JPG With Delphi

  1. Maik says:

    hi!
    this is exactly what i need😀
    thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: