Пример #1
0
def create_image(imageFile):
    pixbuf = load_pixbuf(imageFile)
    image = Clutter.Image()
    pixelFormat = Cogl.PixelFormat.RGB_888
    if pixbuf.get_has_alpha():
        pixelFormat = Cogl.PixelFormat.RGBA_8888
    image.set_data(pixbuf.get_pixels(), pixelFormat, pixbuf.get_width(),
                   pixbuf.get_height(), pixbuf.get_rowstride())
    return image
Пример #2
0
def load_clutter_image_from_resource(resource_path):
    pixbuf = GdkPixbuf.Pixbuf.new_from_resource(resource_path)
    image = Clutter.Image()
    if pixbuf is not None:
        format = Cogl.PixelFormat.RGB_888
        if pixbuf.get_has_alpha():
            format = Cogl.PixelFormat.RGBA_8888
        image.set_data(pixbuf.get_pixels(),
                       format,
                       pixbuf.get_width(),
                       pixbuf.get_height(),
                       pixbuf.get_rowstride())
    return image
Пример #3
0
    def do_allocate(self, box, flags):
        image = Clutter.Image()
        try:
            scaled_image = self.ninepatch.render(int(box.get_width()),
                                                 int(box.get_height()))

            image.set_data(
                data=scaled_image.tostring(),
                pixel_format=Cogl.PixelFormat.RGBA_8888,
                width=box.get_width(),
                height=box.get_height(),
                row_stride=box.get_width() * 4,
            )

            self.set_content(image)
            if self.stage:
                self.stage.set_title(self.old_stage_title)

        except ninepatch.ScaleError:
            if self.stage:
                self.stage.set_title('9 Patch is undersized!')
        self.set_allocation(box, flags)
    def get_texture(self, doc, pagenum, reqscale):

        texture = None
        textureinfo = None

        self.cachelock.acquire()
        c = self.cache[doc][pagenum]
        if len(c) > 0:
            previous = c[0]
            for cur in c:
                curscale, _, _ = cur
                if curscale < reqscale: break
                previous = cur
            _, texture, textureinfo = previous
        readtime = time()
        self.cachelock.release()

        if texture:
            image = Clutter.Image()
            image.set_data(
                texture.get_pixels(), Cogl.PixelFormat.RGBA_8888
                if texture.get_has_alpha() else Cogl.PixelFormat.RGB_888,
                texture.get_width(), texture.get_height(),
                texture.get_rowstride())
            actor = Clutter.Actor()
            actor.set_content(image)
            actor.set_size(texture.get_width(), texture.get_height())

            cloneinfo = CloneInfo(textureinfo.origscale, doc, pagenum,
                                  readtime)
            if FREEING_STRATEGY == "aggressive":
                self.cachelock.acquire()
                self.cacheUse[doc, pagenum, textureinfo.origscale] += 1
                self.cachelock.release()
            return (actor, cloneinfo)
        else:
            return None
Пример #5
0
 def __init__(self):
     super().__init__()
     self.image_res_path = "background_image.png"
     self.background_image = Clutter.Image()
     self.set_content(self.background_image)
     self._load_image()
Пример #6
0
    # Load the texture data from a file
    pixbuf = GdkPixbuf.Pixbuf.new_from_file('redhand.png')

    # Use the correct pixel format depending on whether the image
    # has an alpha channel
    pixel_format = Cogl.PixelFormat.RGB_888
    if pixbuf.get_has_alpha():
        pixel_format = Cogl.PixelFormat.RGBA_8888

    data = pixbuf.read_pixel_bytes()
    width = pixbuf.get_width()
    height = pixbuf.get_height()
    stride = pixbuf.get_rowstride()

    # The Image content knows how to draw texture data
    image = Clutter.Image()
    image.set_bytes(data, pixel_format, width, height, stride)

    # A Stage is like any other actor, and can paint a Content
    stage.set_content_gravity(Clutter.ContentGravity.RESIZE_ASPECT)
    stage.set_content_scaling_filters(Clutter.ScalingFilter.TRILINEAR, Clutter.ScalingFilter.LINEAR)
    stage.set_content(image)

    # Show a label with the current content gravity
    label = 'Content Gravity: Resize Aspect'
    text = Clutter.Text(text=label)
    text.add_constraint(Clutter.AlignConstraint(source=stage, align_axis=Clutter.AlignAxis.BOTH, factor=0.5))
    stage.add_child(text)

    # Change the content gravity on tap/click
    action = Clutter.TapAction()