Squall_FF8 1 Posted 2 hours ago 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
Remy Lebeau 1586 Posted 2 hours ago (edited) 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 36 minutes ago by Remy Lebeau 1 Share this post Link to post
Squall_FF8 1 Posted 2 hours ago 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
Uwe Raabe 2140 Posted 1 hour ago If Image1.Picture.Graphic is not of type TBitmap, referencing Image1.Picture.Bitmap will clear the current content and create an empty TBitmap. 1 1 Share this post Link to post
Remy Lebeau 1586 Posted 31 minutes ago (edited) 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 27 minutes ago by Remy Lebeau Share this post Link to post