Mega Code Archive

 
Categories / Delphi / Graphic
 

How to clear the graphics in a TImage Delphi control

Title: How to clear the graphics in a TImage Delphi control 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?