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".
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
How to resize Image before Upload in Browser
Tutorial | 13 Comments
HTML5: Upload Images with Client Side Resize
Tutorial | 9 Comments
Rename Files sequentially keeping "connected" File Names Pattern
Question | 11 Answers
Rename File to its Folder Name
Tutorial | 0 Comments
Create virtual domains for Apache/XAMPP
Tutorial | 2 Comments
Website Performance: Caching and Expires Header for Images, CSS and JavaScript
Tutorial | 0 Comments
Lazarus: Load File as Byte Array and save Byte Array as File
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.