2016-10-26 18 views
0

私はPySDL2を使用していますが、Windowsで画像を読み込む小さなスクリプトをコーディングしていますが、このエラーメッセージ "ctypes.ArgumentError:引数4::intの代わりにLP_c_intが必要です"私はこの関数 "SDL_QueryTexture"を使用します。これは私のコードです:私は何かのctypesに関連している知っているPySDL2を使用してSDL_QueryTextureを使用する際の問題

"""Simple example for using sdl2 directly.""" 
import os 
import sys 
import ctypes 
from sdl2 import * 

def run(): 
    SDL_Init(SDL_INIT_VIDEO) 
    window = SDL_CreateWindow(b"Hello World", 
            SDL_WINDOWPOS_CENTERED, 
            SDL_WINDOWPOS_CENTERED, 
            459, 536, SDL_WINDOW_SHOWN) 
    render = SDL_CreateRenderer(window, -1, 0)         
    fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), 
         "resources", "self-control.bmp") 
    imageSurface = SDL_LoadBMP(fname.encode("utf-8")) 
    imageTexture = SDL_CreateTextureFromSurface(render, imageSurface) 
    SDL_FreeSurface(imageSurface) 

    sourceRectangle = SDL_Rect() 
    destinationRectangle = SDL_Rect()  
    SDL_QueryTexture(imageTexture, None, None, sourceRectangle.w, sourceRectangle.h) 

    destinationRectangle.x = sourceRectangle.x = 0 
    destinationRectangle.y = sourceRectangle.y = 0 
    destinationRectangle.w = sourceRectangle.w 
    destinationRectangle.h = sourceRectangle.h 

    SDL_RenderCopy(render, imageTexture, sourceRectangle, destinationRectangle) 

    running = True 
    event = sdl2.SDL_Event() 
    while running: 
     while SDL_PollEvent(ctypes.byref(event)) != 0: 
      if event.type == sdl2.SDL_QUIT: 
       running = False 
       break 
     SDL_Delay(10) 

    SDL_DestroyWindow(window) 
    SDL_Quit() 
    return 0  

if __name__ == "__main__": 
    sys.exit(run()) 

、私は誰かが私を助けることができると思います。

答えて

1

SDL_QueryTextureは、結果を書き込むためのintへのポインタを取得します。単純にintを渡すことはできません。回避策は、

w = ctypes.c_int() 
h = ctypes.c_int() 
SDL_QueryTexture(imageTexture, None, None, w, h) 

そしてがw.valueh.valueから結果を得るようなものになるだろう。

あなたは既に表面がありますが、そこから幅と高さを読み取るのはなぜですか?

imageSurface.contents.w, imageSurface.contents.h 
+0

ありがとうございます... –

関連する問題