In I am using cairo with python 3 but am encountering an error where the get_data()
function is returning a memoryview object.
In python 2, the get_data() function returns a Python buffer object for the data of the ImageSurface, for direct inspection or modification.
My script below is supposed to take any svg image and sisplay it in a tkinter frame. In python 3 the getdata()
function does not seem to work with Image.frombuffer()
from rsvg import *
import tkinter as tk
t=tk.Tk()
frame=tk.Frame(t)
def svgPhotoImage(self,file_path_name):
from PIL import Image, ImageTk
import cairo
svg = rsvghandler.Handle(file=file_path_name)
width, height = svg.get_dimension_data()[:2]
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
context = cairo.Context(surface)
svg.render_cairo(context)
tk_image=ImageTk.PhotoImage('RGBA')
image=Image.frombuffer('RGBA',(width,height),surface.get_data(),'raw','BGRA',0,1)
tk_image.paste(image)
return(tk_image)
tk_image=svgPhotoImage(frame, 'example.svg')
frame.configure(image=tk_image)
After tons of searching I still cannot find the equivalent for python 3. Input would be hugely appreciated.