Re: Help Using Gdk_image



On Tue, 2005-11-29 at 15:07 +0000, Michael Noonan wrote:
Hello,

I'm new to using gtk and would really appreciate it if
anybody could help me. 

I'm trying to display an image on the screen thats
created from individual pixel information. I create
the image and then set the indivisual pixels. Then I
try to display the image but I keep getting errors
when I try to execute. 

Am I going about this the wrong way! I've attached the
code below.

Thanks in advance.
Mike

#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdktypes.h>
using namespace std;

this is C++, shouldn't be there

int main( int argc, char *argv[])
{
      GtkWidget *window;
      GtkWidget *canvas;
      GdkVisual *visual;
      GdkImage *image;
      GdkGC *gc;
      
      int i, j;
      unsigned char frame_data[128][64];
              
      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      
      gtk_widget_set_size_request(GTK_WIDGET(window), 1024,
768);
      
      g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
      
      visual = gdk_visual_get_system();
      image = gdk_image_new( GDK_IMAGE_FASTEST, visual, 64,
128 );
      
      gc = gdk_gc_new( GTK_WIDGET( window )->window );
You should probably take the drawable (i.e. GdkWindow) from the drawing
area. Furthermore, you cannot create the GC just yet since window (or
canvas) doesn't have a GdkWindow until it is realised. What you need to
do is to create a global variable that contains the resources you need
and then create the GC when the signal "configure-event" is emitted and
store it in the global variable. You can also pass a heap-allocated
structure via the user_data parameter.

        
      canvas = gtk_drawing_area_new();
      gtk_container_add( GTK_CONTAINER( window ), canvas);
      gtk_widget_show(canvas);
      
      //set the individual pixels
      for( i = 0; i < 128; i++ )
      {
              for( j = 0; j < 64; j++ )
              { 
                      gdk_image_put_pixel( image, i, j, data[i][j] );
              }
      }
              
      gdk_draw_image( GTK_WIDGET( canvas )->window, gc,
image, 0,0,0,0, 64, 128);
Same here. You need to connect to the "expose-event" signal (which also
gives you the area that needs to be redrawn). You need to store the data
in the global variable or in a heap-allocated region that you pass via
the user_data pointer.

Hope this helps,
Axel.





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