1

因此,当我尝试在画布上调整图像大小时,我从 matplotlib 收到“RuntimeError:无法为图像分配内存”。图像是使用 ctypes 的 PyMem_Malloc 分配内存的大型 DICOM (.dcm) 文件。它们被分配了每像素 16 位(它们需要是高分辨率的)。问题出现在我们重新调整画布大小并尝试使用以下方法绘制调整大小的图像后:

self.view.canvas.draw()

这是抛出的特定异常:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_wx.py", line 1355, in _onMotion
    FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=evt)
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 1625, in motion_notify_event
    self.callbacks.process(s, event)
  File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 265, in process
    proxy(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 191, in __call__
    return mtd(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\widgets.py", line 1258, in onmove
    self.update()
  File "C:\Python27\lib\site-packages\matplotlib\widgets.py", line 1236, in update
    self.canvas.restore_region(self.background)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 384, in restore_region
    renderer = self.get_renderer()
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 404, in get_renderer
    self.renderer = RendererAgg(w, h, self.figure.dpi)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 59, in __init__
    self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
RuntimeError: Could not allocate memory for image

图像本身不需要更多分配,对吗?那么这里可能是什么问题呢?matplotlib 是否限制画布可以容纳的内存大小?有人遇到过这个问题吗?

4

0 回答 0