首页 > 编程知识 正文

python中blit方法

时间:2023-05-04 10:21:39 阅读:157696 作者:41

如果能说明想做什么就更好了。 因为那会给你更多的答案:)

据我理解,我想把一张图片放在另一张图片上:

要使此代码正常工作,前提是包含该程序的文件夹还必须包含名为testimage.png和testimage0.jpg的任何图像

已安装PyGame

我已经写了以下代码。 如果你遵循上述前提的话,可以执行这些代码。 导入页面

screen=pygame.display.set _ mode ([ 800,800 ],0,32 ) )。

#initiates screen

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

# testimage0. jpgisloadedintothevariableimage 1

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

# testimage.pngisloadedintothevariableimage 2

while True:

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

# screenisfilledwithablackbackground

sreen.blit(image1,[ 200,200 ]

# here image1 isblittedontoscreenatthecoordinates (200,200 ) )。

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

# here image2 isblittedontoimage1at the coordinates (0,0 ) whichstartsattheupperleftofimage 1

pygame.display.update (

#updates display,which you can just ignore

图像只有包含精灵或图像的曲面。 曲面坐标系始终从左上角(0,0 )开始。 因此,image1的(0,0 )与屏幕的(0,0 )不同。

我拍了程序的照片,编辑箭头说明了我的意见:

我希望这能有帮助。 请记住作为回答接受。 如果你觉得可以接受的话。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。