# Issue with Cairo mask function in a Gtk Window

**URL:** <https://www.ruby-forum.com/t/issue-with-cairo-mask-function-in-a-gtk-window/246422>\
**Category:** Ruby-Gnome 2\
**Created:** [October 12, 2013, 1:50pm UTC](https://www.ruby-forum.com/t/issue-with-cairo-mask-function-in-a-gtk-window/246422 "2013-10-12T13:50:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [October 12, 2013, 1:50pm UTC](https://www.ruby-forum.com/t/issue-with-cairo-mask-function-in-a-gtk-window/246422/1 "2013-10-12T13:50:48Z")

</div>

Hi !  
I’m trying to do smth a little tricky that is explain only in one  
tutorial I found on the net (and it’s a C tuto) It’s to use a pixbuf, or  
eventually a png file as a mask. All seems to work well, except the last  
line.

If I use  
mask = Cairo::ImageSurface.from\_png(“my image\_filepath.png”)  
cr.mask\_surface(mask, x, y).  
The interpreter said there is no mask\_surface method for Cairo::Context  
object.

If I use  
mask = Cairo::ImageSurface.from\_png(“my image\_filepath.png”)  
cr.mask(mask)  
It says that mask is not a Cairo pattern. And it’s the same when I tried  
all I could have imagined to set the mask from a pixbuf.

So has anyone an idea of how I can solve this problem ?  
I attach my code to the message if it could be of any help.

---

<div class="post-metadata">

**Author:** ![67daidalos\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/6/7ba0ec/32.png) [@67daidalos\_S](https://www.ruby-forum.com/u/67daidalos_S)\
**Post date:** [October 13, 2013, 7:18am UTC](https://www.ruby-forum.com/t/issue-with-cairo-mask-function-in-a-gtk-window/246422/2 "2013-10-13T07:18:19Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] issue with Cairo mask function in a Gtk  
Window” on Sat, 12 Oct 2013 13:50:48 +0200,  
“67Daidalos ..” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I use  
> mask = Cairo::ImageSurface.from\_png(“my image\_filepath.png”)  
> cr.mask\_surface(mask, x, y).  
> The interpreter said there is no mask\_surface method for Cairo::Context  
> object.

Try:

cr.mask(mask, x, y)

Cairo::Context#mask accepts both pattern and surface.

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![67daidalos\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/6/7ba0ec/32.png) [@67daidalos\_S](https://www.ruby-forum.com/u/67daidalos_S)\
**Post date:** [October 13, 2013, 7:51am UTC](https://www.ruby-forum.com/t/issue-with-cairo-mask-function-in-a-gtk-window/246422/3 "2013-10-13T07:51:40Z")

</div>

Kouhei S. wrote in post #1124423:

> Try:
> 
> cr.mask(mask, x, y)
> 
> Cairo::Context#mask accepts both pattern and surface.
> 
> ## Thanks,
> 
> kou

Thank you ! It works great !
