How to mask/unmask some of the areas of GdkPixbuf from displaying?

109 Views Asked by At

I have a GdkPixbuf data structure loaded from a svg file (Environment - Python3.7; Linux). Depending upon the area of different object id in svg, I want to mask/unmask the GdkPixBuf Image.

I have searched the python binding for Gtk, Gdk and GdkPixbuf without any luck. Any suggestion is welcome.

Example Code:

from gi.repository import GdkPixbuf

figure_file = 'QWERTY.svg'
width, height = 600, -1
preserve_aspect_ratio = True
im_data = GdkPixbuf.Pixbuf.new_from_file_at_scale(figure_file, width, height, preserve_aspect_ratio)

# Now I want to mask all parts im_data except 20x10 pixel rectangle at pixel(100,120)
maksed_im_data = mask_pixbuf(im_data, 100, 120, 20, 10)

mask_pixbuf function should return masked PixBuf (of the original size) where only the rectangular region of size 20 x 10 centered at (100,120) is visible. Other parts of the returned pixbuf is expected to be transparent.

0

There are 0 best solutions below