设置颜色键时出现问题
我正在使用 python,并且尝试使用 pygame 中的 set_colorkey 函数。我在 Microsoft Paint 中画了一个简单的简笔画,并尝试将颜色键设置为 (255, 255, 255),但这不起作用。我使用像素数组尝试找出背景的实际颜色,结果返回-1。我输入它作为颜色键,但它不起作用。有人可以帮助我吗?
I am using python and I am trying to use the set_colorkey function from pygame. I drew a simple stick figure in Microsoft Paint and I tried to set the colorkey to (255, 255, 255), but that doesn't work. I used a pixel array to try to find out the actual color of the background and it returned -1. I entered that as the colorkey, but it didn't work. Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你所说的“它不起作用”是什么意思,但根据我自己在 pygame 中使用颜色键的经验,将 colorkey 设置在加载图像的同一行会将图像变成 Nonetype 对象。这是因为 set_colorkey 方法不返回图像,而仅设置 colorkey。确保您没有编写如下内容:
此外,编写 set_colorkey(255,255,255) 将导致错误,因为颜色参数是一个参数。这可能不是你的问题,因为我怀疑“它不起作用”意味着它很好并且没有错误,但没有摆脱你想要透明的白色。
请提供更多信息,尤其是您编写的用于设置颜色键的代码。
我希望我有帮助
I am unsure what you mean by "it didn't work", but from my own experience with color keys in pygame, setting the colorkey in the same line as loading the image will turn the image into a Nonetype object. This is because the set_colorkey method doesn't return the image, but only sets the colorkey. Make sure that you didn't write something like:
Additionally, writing set_colorkey(255,255,255) will cause an error, as the color parameter is one argument. That probably isn't your problem, because I suspect that "it didn't work" means that it blitted fine and without error, but did not get rid of the white that you want to make transparent.
Please provide more information, especially exactly what code you wrote to set the colorkey.
I hope I helped