⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-pixmaps.html

📁 gtk的教材和问答集
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>Pixmaps</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Miscellaneous Widgets"HREF="ch-miscwidgets.html"><LINKREL="PREVIOUS"TITLE="Dialogs"HREF="sec-dialogs.html"><LINKREL="NEXT"TITLE="Rulers"HREF="sec-rulers.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-dialogs.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 9. Miscellaneous Widgets</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-rulers.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-PIXMAPS">9.6. Pixmaps</A></H1><P>Pixmaps are data structures that contain pictures. These pictures canbe used in various places, but most commonly as icons on the Xdesktop, or as cursors.</P><P>A pixmap which only has 2 colors is called a bitmap, and there are afew additional routines for handling this common special case.</P><P>To understand pixmaps, it would help to understand how X windowsystem works. Under X, applications do not need to be running on thesame computer that is interacting with the user. Instead, the variousapplications, called "clients", all communicate with a program whichdisplays the graphics and handles the keyboard and mouse. Thisprogram which interacts directly with the user is called a "displayserver" or "X server." Since the communication might take place overa network, it's important to keep some information with the X server.Pixmaps, for example, are stored in the memory of the X server. Thismeans that once pixmap values are set, they don't need to keep gettingtransmitted over the network; instead a command is sent to "displaypixmap number XYZ here." Even if you aren't using X with GTKcurrently, using constructs such as Pixmaps will make your programswork acceptably under X.</P><P>To use pixmaps in GTK, we must first build a GdkPixmap structure usingroutines from the GDK layer. Pixmaps can either be created fromin-memory data, or from data read from a file. We'll go through eachof the calls to create a pixmap.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GdkPixmap *gdk_bitmap_create_from_data( GdkWindow *window,                                        gchar     *data,                                        gint       width,                                        gint       height );</PRE></TD></TR></TABLE><P>This routine is used to create a single-plane pixmap (2 colors) fromdata in memory. Each bit of the data represents whether that pixel isoff or on. Width and height are in pixels. The GdkWindow pointer is tothe current window, since a pixmap's resources are meaningful only inthe context of the screen where it is to be displayed.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GdkPixmap *gdk_pixmap_create_from_data( GdkWindow *window,                                        gchar     *data,                                        gint       width,                                        gint       height,                                        gint       depth,                                        GdkColor  *fg,                                        GdkColor  *bg );</PRE></TD></TR></TABLE><P>This is used to create a pixmap of the given depth (number of colors) fromthe bitmap data specified. <TTCLASS="LITERAL">fg</TT> and <TTCLASS="LITERAL">bg</TT> are the foreground andbackground color to use.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GdkPixmap *gdk_pixmap_create_from_xpm( GdkWindow   *window,                                       GdkBitmap  **mask,                                       GdkColor    *transparent_color,                                       const gchar *filename );</PRE></TD></TR></TABLE><P>XPM format is a readable pixmap representation for the X WindowSystem. It is widely used and many different utilities are availablefor creating image files in this format. The file specified byfilename must contain an image in that format and it is loaded intothe pixmap structure. The mask specifies which bits of the pixmap areopaque. All other bits are colored using the color specified bytransparent_color. An example using this follows below.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GdkPixmap *gdk_pixmap_create_from_xpm_d( GdkWindow  *window,                                         GdkBitmap **mask,                                         GdkColor   *transparent_color,                                         gchar     **data );</PRE></TD></TR></TABLE><P>Small images can be incorporated into a program as data in the XPMformat. A pixmap is created using this data, instead of reading itfrom a file. An example of such data is</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">/* XPM */static const char * xpm_data[] = {"16 16 3 1","       c None",".      c #000000000000","X      c #FFFFFFFFFFFF","                ","   ......       ","   .XXX.X.      ","   .XXX.XX.     ","   .XXX.XXX.    ","   .XXX.....    ","   .XXXXXXX.    ","   .XXXXXXX.    ","   .XXXXXXX.    ","   .XXXXXXX.    ","   .XXXXXXX.    ","   .XXXXXXX.    ","   .XXXXXXX.    ","   .........    ","                ","                "};</PRE></TD></TR></TABLE><P>When we're done using a pixmap and not likely to reuse it again soon,it is a good idea to release the resource usinggdk_pixmap_unref(). Pixmaps should be considered a precious resource,because they take up memory in the end-user's X server process. Eventhough the X client you write may run on a powerful "server" computer,the user may be running the X server on a small personal computer.</P><P>Once we've created a pixmap, we can display it as a GTK widget. Wemust create a GTK pixmap widget to contain the GDK pixmap. This isdone using</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_pixmap_new( GdkPixmap *pixmap,                           GdkBitmap *mask );</PRE></TD></TR></TABLE><P>The other pixmap widget calls are</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">guint gtk_pixmap_get_type( void );void  gtk_pixmap_set( GtkPixmap  *pixmap,                      GdkPixmap  *val,                      GdkBitmap  *mask );void  gtk_pixmap_get( GtkPixmap  *pixmap,                      GdkPixmap **val,                      GdkBitmap **mask);</PRE></TD></TR></TABLE><P>gtk_pixmap_set is used to change the pixmap that the widget is currently

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -