示例#1
0
def load_image(filename, transparent=False):
    image = pygame.image.load(filename)
    image = image.convert()
    if transparent:
        color = image.get_at((0, 0))
        image.set_colorkey(color)
    return image
示例#2
0
def checkDotPoint(x, y, image):
    global dotimage
    global pathImage

    image = dotimage if image == 0 else pathImage
    if image.get_at((int(x), int(y))) == Color('black'):
        return True
    return False
示例#3
0
def change_color(image, from_color, to_color):
    """Change the color of an image object. Return the recolored image"""

    width, height = image.get_size()
    for x in range(width):
        for y in range(height):
            if image.get_at((x, y)) == from_color:
                image.set_at((x, y), to_color)
    return image
示例#4
0
文件: util.py 项目: otfrom/axengine2
 def image(self, rect, colorkey=None, alpha=False):
     rect = Rect(rect)
     if alpha: image = Surface(rect.size).convert_alpha()
     else: image = Surface(rect.size).convert()
     image.blit(self.sheet, (0,0), rect)
     if colorkey is not None:
         if colorkey == -1:
             colorkey = image.get_at((0,0))
         image.set_colorkey(colorkey, RLEACCEL)
     return image
示例#5
0
 def image_at(self, rectangle, colorkey = None):
     "Loads image from x,y,x+offset,y+offset"
     rect = pygame.Rect(rectangle)
     image = pygame.Surface(rect.size).convert()
     image.blit(self.sheet, (0, 0), rect)
     if colorkey is not None:
         if colorkey is -1:
             colorkey = image.get_at((0,0))
         image.set_colorkey(colorkey, pygame.RLEACCEL)
     return image
 def imageAt(self, rectangle, colorkey=-1):
     """
     Note: When calling images_at the rect is the format: (x, y, x + offset, y + offset)
     """
     "Loads image from x,y,x+offset,y+offset"
     rect = Rect(rectangle)
     image = Surface(rect.size).convert()
     image.blit(self.sheet, (0, 0), rect)
     if colorkey is not None:
         if colorkey is -1:
             colorkey = image.get_at((0, 0))
         image.set_colorkey(colorkey, RLEACCEL)
     return image
示例#7
0
 def imageAt(self, rectangle, colorkey=-1):
     """
     Note: When calling images_at the rect is the format: (x, y, x + offset, y + offset)
     """
     "Loads image from x,y,x+offset,y+offset"
     rect = Rect(rectangle)
     image = Surface(rect.size).convert()
     image.blit(self.sheet, (0, 0), rect)
     if colorkey is not None:
         if colorkey is -1:
             colorkey = image.get_at((0, 0))
         image.set_colorkey(colorkey, RLEACCEL)
     return image
示例#8
0
def load_images():
    images = {}

    bpath = __file__.replace(os.path.basename(__file__), '')
    bpath = os.path.join(bpath, 'gfx', 'img')
    image_filenames = os.listdir(bpath)

    for image_filename in image_filenames:
        path = os.path.join("./", bpath, image_filename)
        name = name = os.path.basename(image_filename).split('.')[0].lower()
        image = pygame.image.load(path).convert()
        colorkey = image.get_at((10, 10))
        image.set_colorkey(colorkey)
        images[name] = image
    return images
示例#9
0
	def __determine_font_width(self, image, cur_pix):
		# Our separator color
		color = Color('red')
		width = self.__starting_pix(image, (cur_pix, 0))

		try:
			while color != image.get_at((cur_pix + width, 0)):
				width += 1
				#This is added here because the last characters in some font would be huge
				#just break out for now, until we handle it better
				if width > 10:
					break
		except:
			print "Out of range"

		return width
示例#10
0
def object_image_load(parameters):
    """
    @param parameters: list with picture parameters (NAME, TRANSPARENCY, SIZE)
    @return: image descriptor
    """
    from pygame.constants import RLEACCEL
    from pygame import error
    from pygame.transform import scale
    import pygame.image
    try:
        image = pygame.image.load('res/' + parameters[0] + '.bmp').convert()
    except error:
        error_message("Loading:", "not found " + parameters[0] + '.bmp')
    else:
        image.set_colorkey(image.get_at((0, 0)), RLEACCEL)
        image.set_alpha(parameters[1])
        image = scale(image, (parameters[2][0], parameters[2][1]))
        return image
示例#11
0
    def load_images(self):
        images = {}

        bpath = __file__.replace(os.path.basename(__file__), '')
        bpath = os.path.join(bpath, 'gfx', 'img')
        image_filenames = os.listdir(bpath)

        for image_filename in image_filenames:
            try:
                path = os.path.join("./", bpath, image_filename)
                name = name = os.path.basename(image_filename).split(
                    '.')[0].lower()
                image = pygame.image.load(path).convert()
                colorkey = image.get_at((10, 10))
                image.set_colorkey(colorkey)
                images[name] = image
                msg = "{'load' : True, 'msg' : 'loaded: %s'}" % path
                self.cm.talk(msg)
            except:
                msg = "{'error' : True, 'msg' : 'Failed to load: %s'}" % path
                self.cm.talk(msg)

        self.images = images
示例#12
0
            self.imagelist.reverse()
             
       
# following function and class are used for the displaying of the pointer
#functions to create our resources
def load_image(name, colorkey=None):
    #fullname = os.path.join('c:\\program files\\pygame-docs\\examples\\data', name)
    fullname=name
    try:
        image = pygame.image.load(fullname).convert()
    except pygame.error, message:
        print 'Cannot load image:', name
        raise SystemExit, message
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, RLEACCEL)
    return image, image.get_rect()

def main():
    """this function is called when the program starts.
       it initializes everything it needs, then runs in
       a loop until the function returns."""
    #Initialize Everything
    #this calls the 'main' function when this script is executed
    s = Animation()
    s.initio()
    #s.imagedir = IMAGEDIR
    #s.imagedir = r'C:\_research_cleath\Documents-By-Date-and-Study\2002-09-30-Animation-project\images\bmpSmall'
    #s.imagedir = r'X:\test_label_bug\bmpLarge'
    s.imagedir = r'X:\test_label_bug\bmpSmall'
示例#13
0
def image_line_has_pixels(image, x0, x1, y0, y1):
    for x in xrange(x0, x1 + 1):
        for y in xrange(y0, y1 + 1):
            if any(image.get_at((x, y))):
                return True
    return False
示例#14
0
	def __starting_pix(self, image, cord=(0,0)):
		return 0 if Color('red') != image.get_at(cord) else 1