RE: Regarding JPEG image display in a Window widget.



 
  
    


-----Original Message-----
From: Jean Bréfort [mailto:jean brefort normalesup org]
Sent: Thursday, September 01, 2005 10:55 AM
To: Vinayak J
Cc: gtk-list gnome org
Subject: Re: Regarding JPEG image display in a Window widget.


IMHO, you should use GdkPixbuf provided with Gtk+-2.0 to display the
jpeg images.

Le jeudi 01 septembre 2005 à 09:33 +0530, Vinayak J a écrit :
> 
> Dear Friends, 
>    I'm Vinayak and  I'm working on a program which displays the JPEG
> and the BMP and the XPM images on the screen through a window widget.
> Right now I've written code, which is pasted below, which is
> displaying only the XPM images. 
> I want to display the JPEG and the BMP images also in that window. 
> 
>    As I'm a beginner in this world, I desperately need your help in
> this regard. Please help me. 
> 
>    One more info. I'm making use of the GdkImlib also. But, due to
> unavailability of the proper documents regarding this, I couldn't
> procede. 
> 
> #ifdef HAVE_CONFIG_H 
> #  include <config.h> 
> #endif 
> 
> #include <sys/types.h> 
> #include <sys/stat.h> 
> #include <unistd.h> 
> #include <string.h> 
> 
> #include <gnome.h> 
> 
> #include "support.h" 
> 
> /* This is an internally used function to create pixmaps. */ 
> static GtkWidget* create_dummy_pixmap  (GtkWidget       *widget, 
>                                         gboolean
> gnome_pixmap); 
> 
> /********************************************** 
>  * This is to define an alias for the widgets * 
>  * defined in the main window                 * 
>  **********************************************/ 
> GtkWidget* 
> lookup_widget                          (GtkWidget       *widget, 
>                                         const gchar     *widget_name) 
> { 
>   GtkWidget *parent, *found_widget; 
> 
>   for (;;) 
>     { 
>       if (GTK_IS_MENU (widget)) 
>         parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); 
>       else 
>         parent = widget->parent; 
>       if (parent == NULL) 
>         break; 
>       widget = parent; 
>     } 
> 
>   found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT
> (widget), 
>                                                    widget_name); 
>   if (!found_widget) 
>     g_warning ("Widget not found: %s", widget_name); 
>   return found_widget; 
> } 
> 
> /* This is a dummy pixmap we use when a pixmap can't be found. */ 
> static char *dummy_pixmap_xpm[] = { 
> /* columns rows colors chars-per-pixel */ 
> "1 1 1 1", 
> "  c None", 
> /* pixels */ 
> " ", 
> " " 
> }; 
> 
> /* This is an internally used function to create pixmaps. */ 
> static GtkWidget* 
> create_dummy_pixmap                    (GtkWidget       *widget, 
>                                         gboolean
> gnome_pixmap) 
> { 
>   GdkColormap *colormap; 
>   GdkPixmap *gdkpixmap; 
>   GdkBitmap *mask; 
>   GtkWidget *pixmap; 
> 
>   if (gnome_pixmap) 
>     {       
>            return gnome_pixmap_new_from_xpm_d (dummy_pixmap_xpm); 
>     } 
> 
>   colormap = gtk_widget_get_colormap (widget); 
>   gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap,
> &mask, 
>                                                      NULL,
> dummy_pixmap_xpm); 
>   if (gdkpixmap == NULL) 
>     g_error ("Couldn't create replacement pixmap."); 
>   pixmap = gtk_pixmap_new (gdkpixmap, mask); 
>   gdk_pixmap_unref (gdkpixmap); 
>   gdk_bitmap_unref (mask); 
>   return pixmap; 
> } 
> 
> /* This is an internally used function to create pixmaps. */ 
> GtkWidget* 
> create_pixmap                          (GtkWidget       *widget, 
>                                         const gchar     *filename, 
>                                         gboolean
> gnome_pixmap) 
> { 
>   GtkWidget *pixmap; 
>   GdkColormap *colormap; 
>   GdkPixmap *gdkpixmap; 
>   GdkBitmap *mask; 
>   gchar *pathname; 
> 
>   if (!filename || !filename[0]) 
>         return NULL; 
> //      return create_dummy_pixmap (widget, gnome_pixmap); 
> 
>   pathname = gnome_pixmap_file (filename); 
>   if (!pathname) 
>     {  
>       Dummy_Display(pixmap,filename); 
>  //     g_warning (_("Couldn't find pixmap file: %s"), filename); 
>       return create_dummy_pixmap (widget, gnome_pixmap); 
>     } 
> 
>   if (gnome_pixmap) 
>     { 
>       pixmap = gnome_pixmap_new_from_file (pathname); 
>       g_free (pathname); 
>       return pixmap; 
>     } 
> 
>   colormap = gtk_widget_get_colormap (widget); 
>   gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap,
> &mask, 
>                                                    NULL, pathname); 
>   if (gdkpixmap == NULL) 
>     { 
>       g_warning (_("Couldn't create pixmap from file: %s"),
> pathname); 
>       g_free (pathname); 
>       return create_dummy_pixmap (widget, gnome_pixmap); 
>     } 
>   g_free (pathname); 
> 
>   pixmap = gtk_pixmap_new (gdkpixmap, mask); 
>   gdk_pixmap_unref (gdkpixmap); 
>   gdk_bitmap_unref (mask); 
>   return pixmap; 
> } 
> 
> /* This is an internally used function to create imlib images. */ 
> GdkImlibImage* 
> create_image                           (const gchar     *filename) 
> { 
>   GdkImlibImage *image; 
>   gchar *pathname; 
> 
>   pathname = gnome_pixmap_file (filename); 
>   if (!pathname) 
>     { 
>       g_warning (_("Couldn't find pixmap file: %s"), filename); 
>       return NULL; 
>     } 
> 
>   image = gdk_imlib_load_image (pathname); 
>   g_free (pathname); 
>   return image; 
> } 
> 
> 
> 
> With Regards, 
> 
> Vinayak B. Joshi 
>   

 Hi Vinay,
 
  You can use the API's from gtk+-2.0 : 

  gdk_pixbuf_new_from_file  : to get the Pixbuf.

  gdk_pixbuf_get_pixels : to get the Pixels.

  gdk_pixbuf_get_width : get the width of the Pixbuf.
  gdk_pixbuf_get_height : get the height of the Pixbuf.

  and finall draw it into some Drawing area:

  gdk_draw_rgb_image

  That's all i know , hope that helps and all the best :-).

  Cheers.
  Simith



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