1. Home
  2. Computing & Technology
  3. Delphi Programming

How to clear the graphics in a TImage control

By Zarko Gajic, About.com

The TImage control can be used to display a graphical image - Icon (ICO), Bitmap (BMP), Metafile (WMF), GIF, JPEG, etc. The Picture property (of TPicture type) specifies the image that appears on the image control. There are many ways to assign an image for the TImage component: a TPicture's method LoadFromFile can be used to read graphics from disk, or Assign method can be used to get the image from Clipboard, for example.

However, if you need to clear the image contained in the TImage control, at run time, you'll find that *no* method exist for such a simple task.

Of course, this is not 100% true. Since the graphics displayed in the TImage control is stored in the Picture property, you only need assign "nothing" to it. Here's how (if "Image1" is the name of the TImage control):

Image1.Picture := nil;
Note: to see if there is an image displayed in the TImage, you might be tempted to use "if Image1.Picture = nil ...", BUT this will not work!

Here's how to check Is there an Image in the TImage Delphi Control? Delphi tips navigator:
» How to add leading zero's to a number
« How to exchange Bitmap images between two TImageList components

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TImage
  6. How to clear the graphics in a TImage Delphi control

©2009 About.com, a part of The New York Times Company.

All rights reserved.