本文整理汇总了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,
)
示例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
示例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
示例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)
示例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)))
示例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
示例7: load_image
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import image [as 别名]
def load_image(image_name):
return pygame.image.load(image_name)
示例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()
示例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()
示例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 )
示例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 )
示例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
示例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()
示例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()
示例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...