如何测试 TImage 是否分配有图形?

发布于 2024-08-30 01:02:36 字数 110 浏览 6 评论 0原文

我的程序中的表单上有一个 TImage 组件。

在某些情况下,程序必须测试:

如果“有一个图像分配给 TImage 组件的图片属性”,那么...

我该怎么做?

There's a TImage component on a form in my program.

In some situation, the program must test:

If "there is an image assigned to the picture property of the TImage component" then ...

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城仅有旧梦在 2024-09-06 01:02:36
if Image1.Picture.Graphic = NIL 
then ShowMessage("There is no image.")
else ShowMessage("Image found.");

如果使用位图,您还可以执行以下操作:

if Image.Picture.Bitmap.Empty then ShowMessage("There is no spoon");
if Image1.Picture.Graphic = NIL 
then ShowMessage("There is no image.")
else ShowMessage("Image found.");

If working with bitmaps, you can also do this:

if Image.Picture.Bitmap.Empty then ShowMessage("There is no spoon");
捶死心动 2024-09-06 01:02:36

迟到总比不到好!
正确的方法是:

if Assigned(Image1.Picture.Graphic) then ...

Better late than never!
The right way is:

if Assigned(Image1.Picture.Graphic) then ...

蓝天白云 2024-09-06 01:02:36

你没有说,但我假设你在谈论 Delphi。

可以通过测试来检查TImage控件中是否有位图:

if Image.Picture.Bitmap.Width > 0 then
  // do whatever

You don't say, but I'll assume you're talking about Delphi.

You can check whether there's a bitmap in the TImage control by testing:

if Image.Picture.Bitmap.Width > 0 then
  // do whatever
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文