绘制图像到gtk.DrawingArea? [英] draw an image to gtk.DrawingArea?

查看:251
本文介绍了绘制图像到gtk.DrawingArea?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据此处.

有什么方法可以将图像添加到绘图区域,以便您仍可以在图像上进行绘图?例如邮票,或导入的照片.我尝试添加gtk.Image(),但是gtk.DrawingArea对象没有属性add.

Is there any way to add an image to the drawing area so that you can still draw over the image? Like a stamp, or an imported photo for example. I've tried adding a gtk.Image() but gtk.DrawingArea object has no attribute add.

self.window = gtk.Window((gtk.WINDOW_TOPLEVEL))
self.window.set_title ("Canvas")
self.window.set_position(gtk.WIN_POS_CENTER)
hbox = gtk.HBox(False, 0)
self.window.add(hbox)
self.window.set_resizable(False)

# Create the drawing area
drawing_area = gtk.DrawingArea()
drawing_area.set_size_request(screenWidth-350, screenHeight-100)
hbox.pack_start(drawing_area, True, True, 0)
drawing_area.show()

推荐答案

您必须使用

You have to draw the image (as a gtk.gdk.Pixbuf, not gtk.Image) onto the backing pixmap yourself using gtk.gdk.Drawable.draw_pixbuf(). Only container widgets (widgets that can contain other widgets) have an add() method, and gtk.DrawingArea is not one.

pixbuf = gtk.gdk.pixbuf_new_from_file(image_filename) #one way to load a pixbuf
pixmap.draw_pixbuf(None, pixbuf, 0, 0, x, y, -1, -1, gtk.gdk.RGB_DITHER_NONE, 0, 0)

这篇关于绘制图像到gtk.DrawingArea?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆