【问题标题】:issue displaying multiple images wx.python显示多个图像 wx.python 的问题
【发布时间】:2019-04-03 17:21:30
【问题描述】:

好的,所以我在这里迷路了,我们将不胜感激。我有一个程序可以显示给定时间范围内的所有晶圆图。[下图]当我输入日期 9/1/18- 9/15/18 时,它输出正常。当我做 9/15/18-9/30/18 时,它也可以正常工作,但是当我查询整个月时,我得到一个错误。我开始认为这可能是与内存相关的问题,但我对内存不太了解。我知道python自己处理内存。此外,我确实有 16GB 的 RAM 并使用 64 位架构。该设置是一个 GUI,允许您选择一个文件并选择 2 个日期,然后出现另一个 wx.frame,显示晶圆图。

查询较大日期时收到的错误如下

image = bitmap.ConvertToImage()
wx._core.wxAssertionError: C++ assertion "hbmp" failed at ..\..\src\msw\dib.cpp(139) in wxDIB::Create(): wxDIB::Create(): invalid bitmap

这里是被调用的父函数

def SetBitmapLabel(self, bitmap, createOthers=True):
    """
    Set the bitmap to display normally.
    This is the only one that is required.

    If `createOthers` is ``True``, then the other bitmaps will be generated
    on the fly.  Currently, only the disabled bitmap is generated.

    :param wx.Bitmap `bitmap`: the bitmap for the normal button appearance.

    .. note:: This is the bitmap used for the unselected state, and for all other
       states if no other bitmaps are provided.
    """

    self.bmpLabel = bitmap
    if bitmap is not None and createOthers:
        image = bitmap.ConvertToImage()
        imageutils.grayOut(image)
        self.SetBitmapDisabled(wx.Bitmap(image))

上面的函数在这里被调用

def SetBitmap(self, bmp):
    """
    Sets the bitmap representation of the current selected colour to the button.

    :param wx.Bitmap `bmp`: the new bitmap.
    """

    self.SetBitmapLabel(bmp)
    self.Refresh()

任何帮助将不胜感激,因为此时我不知道从这里去哪里。也许正在工作的 GUI 只能在 32 位下运行?不确定。不确定是否需要图像,但在下面

编辑 感谢下面的人,我发现发生这种情况的原因是因为我的 GDI 对象达到了 10,000 个脚本,这是 Windows 设置的限制。现在我必须为此找到解决方法。可能会发布另一个问题来深入探讨这个

【问题讨论】:

  • 仔细检查 wxwidgets 组件标签的名称以及图像路径。
  • 它在较短的查询中起作用但在较大的查询中失败的任何原因?就标签名称和图像路径而言?
  • 看起来你的内存肯定用完了。

标签: python python-3.x memory-management wxpython wxwidgets


【解决方案1】:

您的 GDI 资源似乎已用完,即创建实际位图对象 (HBITMAP) 失败。不幸的是,在这种情况下,除了显而易见的事情之外,没有太多可以做的事情:创建更少(和/或更小)的位图。

还要检查您是否没有泄漏任何位图,即如果问题仅在您运行应用程序一段时间后才开始出现,则很可能是这种情况。 Windows 下的许多诊断工具(例如Process Explorer)可以向您显示您的进程消耗的 GDI 资源,检查它们是否在程序运行时没有增长。

【讨论】:

  • 嘿,你说得对。脚本达到了一个进程允许的 10k 限制感谢您向我展示了这一点,我永远不会知道
【解决方案2】:

正如 VZ 所说,您似乎用完了 GDI 资源(即位图),这与可用 RAM 无关,而是与操作系统有关。

如果是这样的话,我会走这条路:

  • 将图像存储在 wxImage 的对象中。他们将使用 RAM,但不使用 GDI 资源。
  • 处理每个窗口绘制事件。在此处理程序中,将wxImage 转换为bitmap 并将其传送到窗口。位图现在可以发布了。

【讨论】:

  • @JeffPernia 最好用新代码和你遇到的问题打开一个新问题。
  • 你能简单解释一下第二个要点吗?这让我有点困惑
  • @JeffPernia 你Bind() 某个函数See Events wxPython doc 的wx:EVT_PAINT 类型事件。在此函数中,您将获得正确的 wxImage 并将其显示在窗口中。
【解决方案3】:

遇到同样的问题。简单的解决方案解决了问题:

import subprocess, time

while True:
    cd = "py img_get_xp.py"
    subprocess.Popen(cd)
    time.sleep(600)
    subprocess.Popen('tasklist>task.txt', shell=True).communicate()
    tasks = open('task.txt')
    lines = tasks.read()[::-1]
    pos = lines.find("exe.nohtyp")
    pid = lines[pos - 22:pos - 18][::-1]
    subprocess.call(['taskkill', '/F', '/T', '/PID', pid])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-03
    • 2011-01-02
    • 1970-01-01
    • 2014-09-20
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多