RE: Images.



On Tue, 8 Aug 2000, Gonzalo Montesdeoca wrote:

 Hi Gonzalo,

> 
> On Mon, 7 Aug 2000, Gonzalo Montesdeoca wrote:
> 
> >
> > 	How can draw a image (RGB) only with GTK+ without use GDK ?
> 
>  It seems that drawing images without the use of GDK is very tricky.
>  Why do you want not to use GDK for drawing images? GTK uses it itself - why
> you can't?
> 
> > 	Thanks.
> >
> > 						Gonzalo Montesdeoca
> 
>  Best regards,
>   -Vlad
> 
> Hi Vlad :
> 
> 	I want to use GTK+ because looking for the functions that i use to view
> images, GIMP don't use it. GIMP use a widget preview and i don't know how to
> use. My problem is that in Win32, the image is black on the screen, and i
> don't know why and GIMP do it. if you know why i am grateful that you write
> me a e-mail.
> 	Sorry for my poor english and thanks.

  If you need only to show some not very big image and don't care about
performance, you could convert an image from any format to xpm format and then
show it using gdk - that should work anyway even on win32. If it doesn't, then
it's a bug in gtk/gdk (or it's not implemented yet).
  I've attached a sample file that show xpm file (it could also be found in
the source tree of gtk, in /examples/pixmap/pixmap.c). You could use the same
approach. If even that example doesn't work (I don't expect this :), submit a 
bugreport with details of your configuration.

> 										Gonzalo Montesdeoca
> 

 Best regards,
  -Vlad
/* example-start pixmap pixmap.c */

#include <gtk/gtk.h>


/* XPM data of Open-File icon */
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.    ",
"   .........    ",
"                ",
"                "};


/* when invoked (via signal delete_event), terminates the application.
 */
void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) {
    gtk_main_quit();
}


/* is invoked when the button is clicked.  It just prints a message.
 */
void button_clicked( GtkWidget *widget, gpointer data ) {
    printf( "button clicked\n" );
}

int main( int argc, char *argv[] )
{
    /* GtkWidget is the storage type for widgets */
    GtkWidget *window, *pixmapwid, *button;
    GdkPixmap *pixmap;
    GdkBitmap *mask;
    GtkStyle *style;
    
    /* create the main window, and attach delete_event signal to terminating
       the application */
    gtk_init( &argc, &argv );
    window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    gtk_signal_connect( GTK_OBJECT (window), "delete_event",
                        GTK_SIGNAL_FUNC (close_application), NULL );
    gtk_container_set_border_width( GTK_CONTAINER (window), 10 );
    gtk_widget_show( window );

    /* now for the pixmap from gdk */
    style = gtk_widget_get_style( window );
    pixmap = gdk_pixmap_create_from_xpm_d( window->window,  &mask,
                                           &style->bg[GTK_STATE_NORMAL],
                                           (gchar **)xpm_data );

    /* a pixmap widget to contain the pixmap */
    pixmapwid = gtk_pixmap_new( pixmap, mask );
    gtk_widget_show( pixmapwid );

    /* a button to contain the pixmap widget */
    button = gtk_button_new();
    gtk_container_add( GTK_CONTAINER(button), pixmapwid );
    gtk_container_add( GTK_CONTAINER(window), button );
    gtk_widget_show( button );

    gtk_signal_connect( GTK_OBJECT(button), "clicked",
                        GTK_SIGNAL_FUNC(button_clicked), NULL );

    /* show the window */
    gtk_main ();
          
    return 0;
}
/* example-end */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]