import pygame class imageHandler: def __init__ ( self ): self.pics = dict() def loadFromFile ( self, filename, id=None ): if id == None: id = filename self.pics [ id ] = pygame.image.load ( filename ).convert() def loadFromSurface ( self, surface, id ): self.pics [ id ] = surface.convert() def render ( self, surface, id, position = None, clear = False, size = None ): if clear == True: surface.fill ( ( 0, 0, 0 ) ) if position == None: picX = int ( surface.get_width() / 2 - self.pics [ id ].get_width() / 2 ) picY = int ( surface.get_height() / 2 - self.pics [ id ].get_height() / 2 ) else: picX = position [ 0 ] picY = position [ 1 ] if size == None: surface.blit ( self.pics [ id ], ( picX, picY ) ) else: surface.blit ( pygame.transform.smoothscale ( self.pics [ id ], size ), ( picX, picY ) ) pygame.display.init() screen = pygame.display.set_mode ( ( 640, 480 ) ) handler = imageHandler() handler.loadFromFile ( "images/network.png", "net" ) handler.loadFromFile ( "images/laptop.png", "laptop" ) handler.loadFromFile ( "images/presentation.png", "ppt" ) handler.render ( screen, "net", ( 0, 0 ), True, ( 100, 100 ) ) handler.render ( screen, "laptop", None, False ) handler.render ( screen, "ppt", ( 200, 200 ), None ) handler.loadFromSurface ( screen, "screenshot" ) pygame.display.flip() raw_input() pygame.quit()