If you work with lower-level SDL methods (for example, sdl2.SDL_LoadBMP ), you will have to deal with ctypes conversions, a reference ( byref ), and pointer dereferencing ( .contents , .value ).
So, for a specific question, as you already commented, using print(image.contents.h) will be enough.
However, there are higher-level classes and methods provided by pysdl2 ( sdl2.ext ) that could do most of these conversions for you, if necessary. The code below achieves the same goal without touching ctypes:
import os os.environ["PYSDL2_DLL_PATH"] = os.path.dirname(os.path.abspath(__file__)) import sys import sdl2 import sdl2.ext def main(): sdl2.ext.init() window = sdl2.ext.Window( title="Hello World!", size=(592, 460), flags=sdl2.SDL_WINDOW_SHOWN, position=(sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED)) window.show() renderer = sdl2.ext.Renderer(window) factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer) spriterenderer = factory.create_sprite_render_system(window) image = factory.from_image("exampleimage.bmp") print(image.size[1])
It also uses texturing, using hardware acceleration, instead of surface blitting (software-based).
Finally, using the higher level sdl2.ext , you can also instantiate classes (instead of writing the new sprite class yourself), for example sdl2.ext.sprite.TextureSprite , and implement the h property:
class TextureSprite(sdl2.ext.TextureSprite): @property def h(self): """The height of the TextureSprite.""" return self.size[1] @property def w(self): """The width of the TextureSprite.""" return self.size[0]