我正在尝试将uint8
alpha 值的 numpy 数组(此处为腌制数组)应用到表面,但我不断得到ValueError: unsupported colormasks for alpha reference array
.
s = pygame.Surface((100, 100))
s.fill((126, 126, 126)) # make it grey
pxa = pg.surfarray.pixels_alpha(s)
这是完整的回溯:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-81-8c19259f8aa5> in <module>()
----> 1 pxa = pg.surfarray.pixels_alpha(s)
/usr/lib/python2.7/dist-packages/pygame/surfarray.pyc in pixels_alpha(surface)
206 return numericsf.pixels_alpha (surface)
207 elif __arraytype == "numpy":
--> 208 return numpysf.pixels_alpha (surface)
209 raise NotImplementedError("surface arrays are not supported")
210
/usr/lib/python2.7/dist-packages/pygame/_numpysurfarray.pyc in pixels_alpha(surface)
295 start = 3
296 else:
--> 297 raise ValueError("unsupported colormasks for alpha reference array")
298
299 array = numpy.ndarray \
ValueError: unsupported colormasks for alpha reference array
文档字符串提到需要具有每像素 alpha 值的pixels_alpha
32 位。Surface
我检查了表面位大小Surface.get_bitsize
,并确认它返回32
。话虽如此,我不知道如何检查它是否具有每个像素的 alpha 值。这可能是问题吗?如果是这样,我该如何检查?如果没有,我错过了什么?
谢谢!