当前位置: 首页>>代码示例>>Python>>正文


Python pygame.image方法代码示例

本文整理汇总了Python中pygame.image方法的典型用法代码示例。如果您正苦于以下问题:Python pygame.image方法的具体用法?Python pygame.image怎么用?Python pygame.image使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame的用法示例。


在下文中一共展示了pygame.image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def draw(self, scene):
        with scene.camera.bind_framebuffer(self._fb):
            super().draw(scene)
        with blend_func(scene.ctx, moderngl.ONE, moderngl.ZERO):
            scene.camera.run_shader(
                """\
#version 330 core

in vec2 uv;
out vec4 f_color;
uniform sampler2D image;

void main()
{
    f_color = texture(image, uv);
}
""",
                image=self.tex,
            ) 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:21,代码来源:scene.py

示例2: createGUI

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def createGUI( file ):

   # load movie
   movie = pygame.movie.Movie( file )
   width, height = movie.get_size()

   # initialize display window
   screen = pygame.display.set_mode( ( width, height + 100 ) )
   pygame.display.set_caption( "Movie Player" )
   pygame.mouse.set_visible( 1 )

   # play button
   playImageFile = os.path.join( "data", "play.png" )
   playImage = pygame.image.load( playImageFile ).convert()
   playImageSize = playImage.get_rect()
   playImageSize.center = width / 2, height + 50

   # copy play button to screen
   screen.blit( playImage, playImageSize )
   pygame.display.flip()

   # set arqui_recipe surface for movie's video
   movie.set_display( screen )

   return movie, playImageSize 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:27,代码来源:fig24_05.py

示例3: add_sprite

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def add_sprite(
        self,
        image,
        *,
        pos=(0, 0),
        angle=0,
        anchor_x='center',
        anchor_y='center',
        color=(1, 1, 1, 1),
        scale=1.0
    ):
        spr = Sprite(
            layer=self,
            image=image,
            anchor_x=anchor_x,
            anchor_y=anchor_y,
        )
        spr.pos = pos
        spr.angle = angle
        spr.color = color
        spr.scale = scale
        self.objects.add(spr)
        return spr 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:25,代码来源:layers.py

示例4: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def __init__(
        self,
        screen: pg.Surface,
        x: int,
        y: int,
        width: int,
        height: int,
        image: pg.image,
        image_hover: pg.image = None,
    ):
        """Sets rectangle object for the button."""
        self.screen = screen
        self.image = image
        self.image_hover = image_hover

        self.image = pg.transform.scale(self.image, (width, height))
        self.image_hover = pg.transform.scale(self.image_hover, (width, height))
        self.rect = Rect(x, y, width, height) 
开发者ID:python-discord,项目名称:code-jam-5,代码行数:20,代码来源:button.py

示例5: test_save_colorkey

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def test_save_colorkey(self):
        """ make sure the color key is not changed when saving.
        """
        s = pygame.Surface((10,10), pygame.SRCALPHA, 32)
        s.fill((23,23,23))
        s.set_colorkey((0,0,0))
        colorkey1 = s.get_colorkey()
        p1 = s.get_at((0,0))

        temp_filename = "tmpimg.png"
        try:
            pygame.image.save(s, temp_filename)
            s2 = pygame.image.load(temp_filename)
        finally:
            os.remove(temp_filename)

        colorkey2 = s.get_colorkey()
        # check that the pixel and the colorkey is correct.
        self.assertEqual(colorkey1, colorkey2)
        self.assertEqual(p1, s2.get_at((0,0))) 
开发者ID:wistbean,项目名称:fxxkpython,代码行数:22,代码来源:image_test.py

示例6: _unicode_save

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def _unicode_save(self, temp_file):
        im = pygame.Surface((10, 10), 0, 32)
        try:
            with open(temp_file, 'w') as f:
                pass
            os.remove(temp_file)
        except IOError:
            raise unittest.SkipTest('the path cannot be opened')

        self.assertFalse(os.path.exists(temp_file))

        try:
            pygame.image.save(im, temp_file)

            self.assertGreater(os.path.getsize(temp_file), 10)
        finally:
            try:
                os.remove(temp_file)
            except EnvironmentError:
                pass 
开发者ID:wistbean,项目名称:fxxkpython,代码行数:22,代码来源:image_test.py

示例7: load_image

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def load_image(image_name):
	return pygame.image.load(image_name) 
开发者ID:yaksok,项目名称:yaksok,代码行数:4,代码来源:simplecanvas.py

示例8: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def main():
    global mainDir, fontsChinese
    pygame.init()
    shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
    os.makedirs(OUTPUT_DIR)
    labels = open(os.path.join(OUTPUT_DIR, "labels.txt"), 'w')
    labels.truncate()
    i = 0
    chiIdx = 0
    outDir = None

    # http://stackoverflow.com/questions/50499/how-do-i-get-the-path-and-name-of-the-file-that-is-currently-executing
    selfPath = os.path.abspath(inspect.getfile(inspect.currentframe()))
    mainDir, _ = os.path.split(selfPath)
    dirFonts = os.path.join(mainDir, 'fonts_Chinese')
    fnFonts = filter(lambda fn: os.path.splitext(fn)[1].lower() in [
                     '.ttf', '.otf'], os.listdir(dirFonts))
    fontsChinese = list(
        map(lambda fn: os.path.join(dirFonts, fn), fnFonts))

    chiFiles = sorted(glob.glob('newsgroup/corpus-*.txt'))
    outputPerChiFile = OUTPUT_NUM / len(chiFiles)
    initChineseSource(chiFiles[0])
    chiIdx += 1

    for im, text in generate(OUTPUT_NUM):
        if i % OUTPUT_BATCH == 0:
            outDir = os.path.join(OUTPUT_DIR, str(int(i/OUTPUT_BATCH)))
            os.makedirs(outDir)
        if i != 0 and i % outputPerChiFile == 0:
            initChineseSource(chiFiles[chiIdx])
            chiIdx += 1
        outf = os.path.join(outDir, '%s.jpg' % i)
        # pygame.image.save(im, outf) #pygame
        # im.save(outf) #PIL image
        io.imsave(outf, im)  # scikit-image
        labels.write('%s/%s.jpg\t%s\n' % (int(i/OUTPUT_BATCH),
                                          i, text))
        print('done %s.jpg, text: %s' % (i, text))
        i += 1
    labels.close() 
开发者ID:deepinsight,项目名称:insightocr,代码行数:43,代码来源:gen.py

示例9: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def __init__( self, image ):
      """Initialize object image and calculate rectangle"""
      
      self.image = image
      self.rectangle = image.get_rect() 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:7,代码来源:fig24_06.py

示例10: place

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def place( self, screen ):
      """Place object on the screen"""
      
      return screen.blit( self.image, self.rectangle ) 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:6,代码来源:fig24_06.py

示例11: remove

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def remove( self, screen, background ):
      """Place background over image to remove it"""
      
      return screen.blit( background, self.rectangle,
         self.rectangle ) 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:7,代码来源:fig24_06.py

示例12: loadImage

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def loadImage( self ):
      """Load Player image and calculate rectangle"""

      if self.playerPosition == -1:   # player has crashed
         image = self.crashImage        
      else:
         image = self.movingImages[ self.playerPosition ]

      Sprite.__init__( self, image )
      self.rectangle.centerx = self.centerX
      self.rectangle.centery = self.centerY 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:13,代码来源:fig24_06.py

示例13: moveLeft

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def moveLeft( self ):
      """Change Player image to face one position to left"""

      if self.playerPosition == -1:   # player crashed
         self.speed = 1
         self.playerPosition = 0      # move left of obstacle
      elif self.playerPosition > 0:
         self.playerPosition -= 1

      self.loadImage() 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:12,代码来源:fig24_06.py

示例14: collision

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def collision( self ):
      """Change Player image to crashed player"""

      self.speed = 0   
      self.playerPosition = -1
      self.loadImage() 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:8,代码来源:fig24_06.py

示例15: checkdependencies

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def checkdependencies():
    "only returns if everything looks ok"
    msgs = []

    #make sure this looks like the right directory
    if not os.path.isdir(CODEDIR):
        msgs.append('Cannot locate stuntcat modules')
    if not os.path.isdir('data'):
        msgs.append('Cannot locate stuntcat data files')

    #first, we need python >= 2.7
    if sys.hexversion < 0x2070000:
        errorbox('Requires Python-2.7 or Greater')

    #is correct pg found?
    try:
        import pygame as pg
        if pg.ver < '1.9.4':
            msgs.append('Requires pygame 1.9.4 or Greater, You Have ' + pg.ver)
    except ImportError:
        msgs.append("Cannot import pygame, install version 1.9.4 or higher")
        pg = None

    #check that we have FONT and IMAGE
    if pg:
        if not pg.font:
            msgs.append('pg requires the SDL_ttf library, not available')
        if not pg.image or not pg.image.get_extended():
            msgs.append('pg requires the SDL_image library, not available')

    if msgs:
        msg = '\n'.join(msgs)
        errorbox(msg)



#Pretty Error Handling Code... 
开发者ID:pygame,项目名称:stuntcat,代码行数:39,代码来源:cli.py


注:本文中的pygame.image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。