python - Is there a function in Pygame to save a portion of the screen as an image?
问题描述
I am working on making a drawing program in Pygame. All features are basically complete except for the ability to save your image. Is there any built in Pygame function that does this, or will I have to find some other way (E.G. taking a screenshot or something).
解决方案
screen
是一个Surface对象,它具有subsurface(Rect)方法来获取表面的一部分 - 这部分也是一个Surface
对象。
还有函数pygame.image.save(surface, filename)
其他方法:在开始时创建较小的Surface
并在此表面上绘制(而不是直接在 上绘制screen
)和blit()
此表面screen
以显示它并将save()
此表面归档。
您甚至可以使用许多表面并将它们列在列表中以创建功能Undo
。当您使用新工具时,您复制表面并将其放在列表中。当您使用时Undo
,您会从列表中获得最后一个表面。
推荐阅读
- python - 使用数据着色器作为线从数据框中绘制多个组
- docker - 使用 ASP.NET Core 中的部分将 docker 机密读入配置
- excel - 从另一个工作簿 VBA>> 运行时 1004 错误中选择列
- php - 每天的最新价值 - Laravel Eloquent
- javascript - 在待办事项列表中隐藏/显示不同的内容,并使用 JavaScript 一次显示一个内容
- java - 使用 Gradle 和 IntelliJ 的 JavaFX FatJar
- pytorch - 断言批处理不在键中并且 ptr 不在键中
- android - 如何通过 OpenGL ES 将图像流式传输到 Android Surface
- asynchronous - 读取 CSV 并在 Blazor Server 中作为列表返回
- javascript - 如何在刺激 js 控制器中使用私有方法?