【问题标题】:Is there a way to increase the size of the background image in turtle?有没有办法增加海龟背景图像的大小?
【发布时间】:2022-01-23 08:42:14
【问题描述】:

我正在尝试用 python 3 制作一个需要背景图片的游戏。我已经有了图像。这里的问题是我的图像与大屏幕相比看起来很小。我不想改变屏幕的大小,因为那样我就不得不重做屏幕上其他对象的所有坐标。有什么办法可以增加背景图片的大小?

附言。我正在使用 Python 3 和 VS 代码。

提前致谢! 这是小图的样子。enter image description here

【问题讨论】:

  • 请分享你的代码和你得到的输出。

标签: python python-3.x resize background-image


【解决方案1】:

为了增加图像的大小,您还需要增加分辨率。

假设你使用的是windows,用Microsoft Photos打开png,然后点击右上角的三个水平点。

将打开一个下拉菜单,按顶部第三个标记为“调整大小”的选项

在此之后,点击“定义自定义尺寸”,您可以随意调整图像的尺寸。

然后,只需保存调整大小的图像,并在您的项目中使用它。

【讨论】:

  • 我刚试过这个方法,还是不行。还有其他建议吗?
【解决方案2】:

您也可以使用 CV2 库来做到这一点

import cv2
image=cv2.imread("image.png")

scale_percent=1.5

width=int(image.shape[1]*scale_percent)

height=int(image.shape[0]*scale_percent)

dimension=(width,height)

resized = cv2.resize(image,dimension, interpolation = cv2.INTER_AREA)

print(resized.shape)

cv2.imwrite("output.png",resized)

或者你也可以使用 PIL 库

from PIL import Image

image = Image.open("image.png")

image.save("output.png", dpi=(image.size[0]*1.5,image.size[1]*1.5))

【讨论】:

  • 您可以根据需要添加比例百分比
猜你喜欢
  • 2021-01-30
  • 1970-01-01
  • 2018-02-27
  • 2014-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多