How to Clear the Graphics in a TImage Control

A short Delphi code block saves the day

girl programming on a desktop computer

Teresa Short/Getty Images

 

Delphi programmers use the TImage control to display an image. These are files that end in extensions including ICO, BMP, WMF, WMF, GIF, and JPG. The Picture property specifies the image that appears in the TImage control. Delphi supports several different methods for assigning an image for the TImage component: a TPicture's method LoadFromFile reads graphics from disk or the Assign method obtains the image from Clipboard, for example.

In the absence of a direct command to clear the Picture property, you'll need to assign a "nil" object to it. Doing so essentially blanks the image.

For a TImage control named Photo, use either of two methods to clear the assigned graphic:

{code:delphi}
Photo.Picture := nil;
{code}

or:

{code:delphi}
Photo.Picture.Assign(nil);
{code}

Either code block will clear the picture from your TImage control. The first approach asserts a nil value to the Picture property; the second approach assigns a nil through the use of a method. 

Format
mla apa chicago
Your Citation
Gajic, Zarko. "How to Clear the Graphics in a TImage Control." ThoughtCo, Feb. 16, 2021, thoughtco.com/clear-the-graphics-in-timage-control-1057545. Gajic, Zarko. (2021, February 16). How to Clear the Graphics in a TImage Control. Retrieved from https://www.thoughtco.com/clear-the-graphics-in-timage-control-1057545 Gajic, Zarko. "How to Clear the Graphics in a TImage Control." ThoughtCo. https://www.thoughtco.com/clear-the-graphics-in-timage-control-1057545 (accessed April 19, 2024).