python - How can I get pixels from cairo.ImageSurface? -
i made python program draws black rectangle white circle inside when click on button. use gtk.drawingarea
, cairo.imagesurface
. code following.
class app: def __init__(self, width, height): self.surface = cairo.imagesurface(cairo.format_argb32, width, height) # builder self.builder = gtk.builder() self.builder.add_from_file('ventana.glade') go = self.builder.get_object # widgets self.window = go('window') self.drawingarea = go('drawingarea') self.button = go('button') signals = { 'gtk_main_quit' : gtk.main_quit, 'draw' : self.draw } self.builder.connect_signals(signals) self.window.show_all() def draw(self, widget): context = self.drawingarea.get_window().cairo_create() context.set_source_surface(self.surface) context.set_source_rgba(0.0, 0.0, 0.0, 1.0) context.rectangle(0, 0, self.surface.get_width(), self.surface.get_height()) context.fill() context.translate(10, 10) context.arc(0, 0, 10, 0, 2 * pi) context.set_source_rgba(1.0, 1.0, 1.0, 1.0) context.fill()
i following window.
it works fine, need rgb values of pixels of picture, tried doing map(ord, self.surface.get_data())
, list of zeros.
how can list rgb of pixels?
and have problem: when minimize window or change window, drawing erases. possible avoid this?
i don't know getting color drawing, connect window 'configure-event' (event being state of window changed) , call drawingarea.queue_draw ()
Comments
Post a Comment