python中blit的意思_在python中,如何在特定图像的区域内blit图像?

如果你能解释一下你想做什么会更好,因为它会给你更多的答案:)

根据我的理解,你想把一个图像放到另一个图像上:

为了使此代码起作用,设置了以下前提条件:包含程序的文件夹还包含名为testimage.png和testimage0.jpg的任意图像

PyGame已安装

我已经编写了以下代码,如果您遵循上述前提,您可以运行这些代码:import pygame

screen = pygame.display.set_mode([800, 800], 0, 32)

#initiates screen

image1 = pygame.image.load('testimage0.jpg')

#testimage0.jpg is loaded into the variable image1

image2 = pygame.image.load('testimage.png').convert_alpha()

#testimage.png is loaded into the variable image2

while True:

screen.fill([0, 0, 0])

#screen is filled with a black background

screen.blit(image1, [200, 200])

#here image1 is blitted onto screen at the coordinates (200,200)

image1.blit(image2, [0, 0])

#here image2 is blitted onto image1 at the coordinates (0,0) which starts at the upper left of image1

pygame.display.update()

#updates display, which you can just ignore

图像只是带有精灵或图片的曲面。曲面的坐标系总是从左上角(0,0)开始,这就是为什么image1的(0,0)与屏幕的(0,0)不同的原因。

我拍了一张程序的照片并编辑了一些箭头来解释我的观点:

d7c6fa2c7c33bb3a29359be063a1d7c5.png

希望这是一个帮助,记住接受作为答案,如果你觉得可以接受。

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值