Zulko / gizeh

Simple Vector Graphics for Python
Other
709 stars 69 forks source link

Copying part of a surface to another surface #35

Open StephanvanSchaik opened 6 years ago

StephanvanSchaik commented 6 years ago

Hi,

Using cairocffi, one can copy part of the surface to another by doing something along the lines of:

ctx = surface.get_new_context()
ctx.set_source_surface(old_surface._cairo_surface, 0, 0)
ctx.rectangle(x, y, width, height)
ctx.fill()

I have tried to use gizeh.rectangle() in combination with gizeh.ImagePattern() using the old surface to achieve the same effect, but passing a gizeh.Surface to gizeh.ImagePattern() does not seem to work. I saw that it should be possible to use surface.get_npimage() instead, but I rather avoid the overhead of converting it to a numpy array and back to a Cairo surface.

Is there another way to achieve the same effect?

edit: I also tried using surface.get_npimage() and passing that to gizeh.ImagePattern() instead, but that also fails with: "TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('uint8') with casting rule 'same_kind'"

Yours sincerely, Stephan.