Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在PyGame和PyOpengl中导入裁剪的图像_Python_Image_Pygame_Crop_Pyopengl - Fatal编程技术网

Python 在PyGame和PyOpengl中导入裁剪的图像

Python 在PyGame和PyOpengl中导入裁剪的图像,python,image,pygame,crop,pyopengl,Python,Image,Pygame,Crop,Pyopengl,如何在PyGame中裁剪图像并将其保存为2个OpenGL纹理 这是我加载完整图像的代码: def loadImage(image): img = pygame.image.load(image)) textureData = pygame.image.tostring(img, "RGBA", 1) texture = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, texture) glTexImage2D(

如何在PyGame中裁剪图像并将其保存为2个OpenGL纹理

这是我加载完整图像的代码:

def loadImage(image):
    img = pygame.image.load(image))
    textureData = pygame.image.tostring(img, "RGBA", 1)

    texture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, texture)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.get_width(), img.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData)

    return texture

是否可以使用图像的裁剪部分创建
textureData
,或者可以使用OpenGL函数完成此操作?我发现您可以将
img.get_height()
替换为
img.get_height()/2
,如果您愿意的话,但您无法选择一个不从(0,0)开始的矩形通过更改第4和第5个参数

您可以将图像的一部分
blit()
放在新的、更小的表面上。或者尝试使用
pygame.Surface.subground()
-谢谢,我使用了pygame.Surface.subground(),效果很好