GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to get pixmap from a gtk.Image?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Sun Nov 30, 2008 8:09 pm    Post subject: How to get pixmap from a gtk.Image? Reply with quote

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

>>> img = gtk.Image()
>>> img.get_pixmap()
(None, None)
>>> img.set_from_file('a.xpm')
>>> img.get_pixmap()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: image should be a GdkPixmap or empty
>>> img.get_pixmap()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: image should be a GdkPixmap or empty


get_image should return gtk.gdk.image but it gave the same error:
Code: (Plaintext)
1
2
3
4
5
6

img.get_image()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: image should be a GdkImage or empty
Back to top
tadeboro
Never Seen the Sunlight


Joined: 23 Jul 2008
Posts: 2114
Location: Slovenia

PostPosted: Sun Nov 30, 2008 10:03 pm    Post subject: Reply with quote

Hi.

What does the
Code: (Python)
1
img.get_storage_type()
return?
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 936
Location: Falun, WI USA

PostPosted: Sun Nov 30, 2008 10:15 pm    Post subject: Reply with quote

get_storage_type should return this:
Code: (Plaintext)
1
<enum GTK_IMAGE_PIXBUF of type GtkImageType>

which means that you can't directly get a GdkPixmap, you can only get a GdkPixbuf, see here:
http://library.gnome.org/devel/gtk/stable/GtkImage.html#GtkImageType
You can draw a GdkPixbuf on a GdkPixmap if you need a pixmap though:
C
http://library.gnome.org/devel/gdk/stable/gdk-Drawing-Primitives.html#gdk-draw-pixbuf
PyGTK
http://pygtk.org/docs/pygtk/class-gdkdrawable.html#method-gdkdrawable--draw-pixbuf
Back to top
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Mon Dec 01, 2008 2:25 pm    Post subject: Reply with quote

thanks (I didn't try yet)

Why is there method "get_pixmap" if we can use it only if the image is empty?
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 936
Location: Falun, WI USA

PostPosted: Mon Dec 01, 2008 4:19 pm    Post subject: Reply with quote

You could also use it if you created your image with gtk.image_new_from_pixmap
C
http://library.gnome.org/devel/gtk/stable/GtkImage.html#gtk-image-new-from-pixmap
PyGTK
http://pygtk.org/docs/pygtk/class-gtkimage.html#function-gtk--image-new-from-pixmap
Back to top
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Tue Dec 02, 2008 10:41 pm    Post subject: Reply with quote

I don't understand how to do it.

gtk.gdk.Drawable.draw_pixbuf is on;y render part of the pixbuf.

I guess it render to pixmap, but to where and how do I get it?


Why should I use get_pixmap() if it work only if the image create from pixmap? I can take the orginal pixmap
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 936
Location: Falun, WI USA

PostPosted: Wed Dec 03, 2008 12:23 am    Post subject: Reply with quote

nadavvin wrote:
gtk.gdk.Drawable.draw_pixbuf is only render part of the pixbuf.

What do you mean by this? The src_[xy], dest_[xy], width and height parameters should control how much is rendered.

Can I ask why you need to use a GdkPixmap? Maybe there's an alternative that will work better for you...
Back to top
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Wed Dec 03, 2008 10:00 am    Post subject: Reply with quote

dreblen wrote:

Can I ask why you need to use a GdkPixmap? Maybe there's an alternative that will work better for you...


I want to create customize windowfrom SVF image, therefore I need to get the mask of it, so I could pass it to the input_shape_combine_mask method.
Back to top
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Wed Dec 03, 2008 10:52 am    Post subject: Reply with quote

tadeboro wrote:
Hi.

What does the
Code: (Python)
1
img.get_storage_type()
return?


sorry, I didn't notice your response:
Code: (Plaintext)
1
2
3
4
5
6
7

>>> img = gtk.Image()
>>> img.set_from_file('1.svg')
>>> print img.get_storage_type()
<enum GTK_IMAGE_PIXBUF of type GtkImageType>
>>>
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 936
Location: Falun, WI USA

PostPosted: Wed Dec 03, 2008 6:36 pm    Post subject: Reply with quote

dreblen wrote:
nadavvin wrote:
gtk.gdk.Drawable.draw_pixbuf is only render part of the pixbuf.

What do you mean by this? The src_[xy], dest_[xy], width and height parameters should control how much is rendered.

You never really answered this question. What exactly is happening right now (i.e. what isn't working)?
Back to top
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Wed Dec 03, 2008 7:07 pm    Post subject: Reply with quote

dreblen wrote:
dreblen wrote:
nadavvin wrote:
gtk.gdk.Drawable.draw_pixbuf is only render part of the pixbuf.

What do you mean by this? The src_[xy], dest_[xy], width and height parameters should control how much is rendered.

You never really answered this question. What exactly is happening right now (i.e. what isn't working)?


I don't know how should I use it. draw_pixbuf draw a pixbuf from a part of other pixbuf. How do I use it to get the pixmap?
Back to top
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Wed Dec 03, 2008 7:42 pm    Post subject: Reply with quote

I made it :P .

I found the method "render_pixmap_and_mask":
http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--render-pixmap-and-mask

Thanks for your help.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP