610 Votes

Delphi: Load JPEG image to TBitmap

Tutorial by Delphian | Last update on 2021-05-13 | Created on 2012-07-17

Today I want to show you how to load a JPG image from a file into a TBitmap in Delphi, for example, to edit this image in an arbitrary way.

On the top of our unit, we have to add the unit "JPEG" to our uses clause:

uses Windows, ... ,JPEG;

And here is our code that loads the JPG and saves it in the bitmap:

procedure TForm1.Button1Click(Sender: TObject);
var
   jpg: TJpegImage;
   bmp: TBitmap;
begin
   jpg := TJpegImage.Create;
   jpg.LoadFromFile('C:\image.jpg');
 
   bmp := TBitmap.Create;
   bmp.Assign(jpg);
 
   // Image Processing
 
   bmp.free;
   jpg.free;
end;

First, we create a new empty jpg image and we are using LoadFromFile to load an arbitrary image to it.

After that, we create an empty bitmap and with "Assign", we can load our "jpg" to the bitmap.

Then we can carry out any desired edits and afterwards, we should not forget to free both "bmp" and "jpg".

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Rename File to its Folder Name

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.