[英]draw an image to gtk.DrawingArea?
I'm writing a PyGtk paint program based on the basic tutorial found here . 我正在根据此处找到的基本教程编写PyGtk绘画程序。
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
. 我尝试添加
gtk.Image()
但gtk.DrawingArea
对象没有属性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()
. 您必须使用
gtk.gdk.Drawable.draw_pixbuf()
将图像(作为gtk.gdk.Pixbuf
,而不是gtk.Image
)绘制到支持的像素图上。 Only container widgets (widgets that can contain other widgets) have an add()
method, and gtk.DrawingArea
is not one. 只有容器窗口小部件(可以包含其他窗口小部件的窗口小部件)具有
add()
方法,而gtk.DrawingArea
不是一个。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.