コード例 #1
0
ファイル: image.py プロジェクト: j-waters/Aiopa-Web-Server
def load_basic(file, namehint=''):
    '''Load BMP image from a file.

    :see: `load`

    :Parameters:
        `file` : str or file-like object
            Image file or filename to load.
        `namehint` : str
            Ignored, for compatibility.

    :rtype: `Surface`
    '''
    #if not hasattr(file, 'read'):
    #    surf = SDL_LoadBMP(file)
    #else:
    #    rw = SDL_RWFromObject(file)
    #    # XXX Differ from pygame: don't freesrc when we didn't allocate it
    #    surf = SDL_LoadBMP_RW(rw, 0)

    _img = JSConstructor(window.Image)()
    _img.src = file

    _img.canvas = html.CANVAS()

    def img_onload(*args):
        #http://www.jaypan.com/tutorial/javascript-passing-arguments-anonymous-functions-without-firing-function
        #the onload files very slow so variables get messed up so we have
        #to use args[0].path[0] to figure out the correct image
        console.log(args)
        if hasattr(args[0], 'target'):  # Firefox
            this = args[0].target
        else:  #chrome
            this = args[0].path[0]

        this.canvas.width = this.width
        this.canvas.height = this.height
        this.canvas.getContext('2d').drawImage(this, 0, 0)
        #this.loaded=True

    _img.onload = img_onload
    return _pygame_surface.Surface(surf=_img.canvas)
コード例 #2
0
def load_basic(file, namehint=''):
    '''Load BMP image from a file.

    :see: `load`

    :Parameters:
        `file` : str or file-like object
            Image file or filename to load.
        `namehint` : str
            Ignored, for compatibility.

    :rtype: `Surface`
    '''
    #if not hasattr(file, 'read'):
    #    surf = SDL_LoadBMP(file)
    #else:
    #    rw = SDL_RWFromObject(file)
    #    # XXX Differ from pygame: don't freesrc when we didn't allocate it
    #    surf = SDL_LoadBMP_RW(rw, 0)


    _img=JSConstructor(window.Image)()
    _img.src=file

    _img.canvas=html.CANVAS()
    def img_onload(*args):
        #http://www.jaypan.com/tutorial/javascript-passing-arguments-anonymous-functions-without-firing-function
        #the onload files very slow so variables get messed up so we have
        #to use args[0].path[0] to figure out the correct image
        console.log(args)
        if hasattr(args[0], 'target'):   # Firefox
           this=args[0].target
        else:                            #chrome
           this=args[0].path[0]

        this.canvas.width=this.width
        this.canvas.height=this.height
        this.canvas.getContext('2d').drawImage(this,0,0)
        #this.loaded=True

    _img.onload=img_onload
    return _pygame_surface.Surface(surf=_img.canvas)