INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Delphi Imaging

How do I load any format of image into a TBitmap? by djjd47130
Posted: 17 Jun 12

It is rather common that developers wish to load various types of files into a TBitmap for manipulation, such as JPEG, PNG, or TIFF. The TBitmap is widely used as the most standard graphic for performing any type of imaging in Delphi. The question is - how to load any format of image into a TBitmap?

Delphi VCL's Graphics unit contains another class called TWICImage. This class, based on a TGraphic (just like a TBitmap), allows you to load virtually any type of image file. WIC Image stands for Windows Imaging Component. It wraps the functionality of Microsoft's WIC image. The formats which are supported depend on the formats which are registered inside of Windows.

IMPORTANT: TWICImage is only available on Windows XP SP3 or higher operating systems and relies on DirectX runtime. If your application is expected to run apart from these requirements, then you will need to recognize this yourself and handle your imaging differently.

TWICImage is used very similarly to the TBitmap. You can use LoadFromFile() and SaveToFile() for simple file loading/saving, and Assign() to/from other TGraphic classes.

For example,

CODE

procedure TForm1.Button1Click(Sender: TObject);
var
W: TWICImage;
B: TBitmap;
begin
W:= TWicImage.Create;
try
W.LoadFromFile('C:\Original PNG File.png');
B:= TBitmap.Create;
try
B.Assign(W);
B.SaveToFile('C:\New BMP File.bmp');
finally
B.Free;
end;
finally
W.Free;
end;
end;

This loads a PNG file into a WIC Image, assigns it to a Bitmap, and saves it to a BMP file.

The TWICImage contains a property called ImageFormat which determines the format of the image (once loaded). You can change this format to change the way the image is handled, and eventually the way that it is saved back to a file.

Here are the possible property values for TWICImage.ImageFormat:
> wifBmp
> wifPng
> wifJpeg
> wifGif
> wifTiff
> wifWMPhoto
> wifOther

Here's Embarcadero's documentation on the TWICImage:

http://docwiki.embarcadero.com/Libraries/en/Vcl.Gr...


Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close