简体   繁体   English

Pygame旋转导致图像卡死

[英]Pygame rotate causes image to stutter

I honestly have no idea why this doesn't work. 老实说,我不知道为什么这行不通。 The rotate cause the image to scale up and down constantly. 旋转导致图像不断放大和缩小。 I looked around and haven't found a solution to my problem. 我环顾四周,但没有找到解决问题的方法。 Main http://tinypaste.com/1c5025fa Module http://tinypaste.com/f42f9c58 主要http://tinypaste.com/1c5025fa模块http://tinypaste.com/f42f9c58

Also can someone explain why this program's box abruptly stops rotating? 也有人可以解释为什么该程序的框突然停止旋转吗? Etc 'http://tinypaste.com/82b3b30e' (remove the quotes, I'm not allowed to post more than 2 hyperlinks) 等“ http://tinypaste.com/82b3b30e”(删除引号,不允许发布两个以上的超链接)

From what I can tell, the scaling that you're seeing is a sort of artifact of how the rotation operation works. 据我所知,您所看到的缩放比例是旋转操作如何工作的一种人工产物。 As a rectangle is rotated, the bounding box will necessarily be larger than the original rectangle. 随着矩形的旋转,边框必定会比原始矩形大。 See for example, the blue rectangle in the image, below. 例如,请参见下面的图像中的蓝色矩形。 R is the radius of the rectangle...so when it's rotated, the rectangle sweeps out the area covered by the red circle in the second image. R是矩形的半径...因此,旋转矩形时,矩形会扫出第二张图像中红色圆圈所覆盖的区域。 The bounding box for the rotation is the now the gray rectangle. 旋转的边界框现在是灰色矩形。 pygame has to fill in both the red area and the gray area. pygame必须同时填写红色区域和灰色区域。 What color does pygame use to fill in the padding area? pygame使用什么颜色填充填充区域?

The pygame.transform.rotate docs say... pygame.transform.rotate文档说...

"Unless rotating by 90 degree increments, the image will be padded larger to hold the new size. If the image has pixel alphas, the padded area will be transparent. Otherwise pygame will pick a color that matches the Surface colorkey or the topleft pixel value." “除非以90度为增量旋转,否则图像将被较大地填充以保持新的尺寸。如果图像具有像素alpha,则填充区域将是透明的。否则pygame将选择与Surface colorkey或左上像素值匹配的颜色”。

So, the solution is to explicitly set the color key or alpha value for the image (in your case, when you construct your saved_image surface.) Then, when the saved_image is rotated, the newly produced image will have the padding area filled with the appropriate color. 因此,解决方案是显式设置图像的颜色键或Alpha值(在您的情况下,当您构造Saved_image曲面时。)然后,当旋转saved_image时,新生成的图像的填充区域将被填充为适当的颜色。

Give it a go and see if that works. 试一试,看看是否可行。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM