Jump to content
Squall_FF8

Is TImage empty

Recommended Posts

Hey Guys,

I have TImage that in run-time I can load with png or jpg.
1. How to check is the TImage empty (aka no image loaded?

2. How to erase the loaded image? (when an image is loaded)

Share this post


Link to post
2 hours ago, Squall_FF8 said:

1. How to check is the TImage empty (aka no image loaded?

Check the TImage.Picture.Graphic and TGraphic.Empty properties:

if (Image1.Picture.Graphic = nil) or Image.Picture.Graphic.Empty then
2 hours ago, Squall_FF8 said:

2. How to erase the loaded image? (when an image is loaded)

You can assign nil to the TImage.Picture property:

Image1.Picture := nil;
// same as:
// Image1.Picture.Assign(nil);

Or to its Graphic property:

Image1.Picture.Graphic := nil;

 

Edited by Remy Lebeau
  • Thanks 1

Share this post


Link to post

Thank you @Remy Lebeau!

 

BTW do you know, why Image1.Picture.Bitmap.Empty clears the image? It is suppose the return a value, not to destroy an image

Share this post


Link to post

If Image1.Picture.Graphic is not of type TBitmap, referencing Image1.Picture.Bitmap will clear the current content and create an empty TBitmap.

  • Like 1
  • Thanks 1

Share this post


Link to post

Yes, and this is documented behavior:

https://docwiki.embarcadero.com/Libraries/en/Vcl.Graphics.TPicture.Bitmap

Quote

Use Bitmap to reference the picture object when it contains a bitmap. If Bitmap is referenced when the picture contains a Metafile or Icon graphic, the graphic won't be converted (Types of Graphic Objects). Instead, the original contents of the picture are discarded and Bitmap returns a new, blank bitmap.

Where it says "a Metafile or Icon graphic", it really means "any non-Bitmap graphic" instead.

 

Use the TPicture.Graphic property when you need to access as-is whatever TGraphic descendant is currently loaded in the TPicture.  Use the TPicture.Bitmap property instead when you specifically need a TBitmap.

Edited by Remy Lebeau

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×