First:   

I am working on a dark-field microscopic tracking program. This program is old (2012), we got a new camera but this camera can´t be captured with a capture program. So I need to write a "capture program" for this camera with the SDK (Software development kit) from the company of the camera.

The tracking program is writen in C and GTK 2, so I would like to have the "capture program" in C and GTK 2 too, so I can just put the "capture program" in my tracking program. I can take a picture inside the "capture program" and show it as `gtk_image_new_from_pixbuf`.

Problem:   

After being able to take pictures I found out that the dark-field microscope is not able to let you set the focus for the camera with your eyes. So now I need to capture a "live image", video or how ever you want to call it.   

My idea was to use a timer so the camera will take a picture every second and display it as an image so the program has to delete the old image and show the new one.
But that doesn´t happen I am pretty sure that there is no problem with the camera, because it shows the first image. My guess is that the pixbuf isn´t cleared and that causes that there is no new image shown.  

The "capture program" doesn´t have to stay as a C/Gtk2 program but as I am not a computer scientist I just have no idea how to get the images into the tracking program if they are different.   

Code:   

I know that `gdk_pixbuf_new_from_data` has a starde of `width*1` and not `width*3` that is no problem.

```
#include <gtk/gtk.h>
#include <stdlib.h>

unsigned short *buffer = NULL;
long imageSize = 0;

void draw_call (GtkWidget *window, GdkEvent *event, gpointer data){

    (void)event; (void)data;
    GdkPixbuf *pix;
    GtkWidget* image;
    image = gtk_image_new();

    free (buffer);
    long result = NOERR;

//camera commands had to be changed 
    result = getImageSizeFromCamera( &imageSize);

    result = SetBitsPerPixel(8);

    buffer = (unsigned short *) malloc( imageSize*2);

    result = takePicture(camera, buffer, imageSize/2, NULL, NULL);

    result = stopTakingPicture (camera);
//end of camera commands

    pix = gdk_pixbuf_new_from_data ((unsigned int *) buffer, GDK_COLORSPACE_RGB,FALSE, 8,
               1936, 1460, 1936*1, pixbuf_free, NULL);

    image = gtk_image_new_from_pixbuf(pix);

    return image;
gtk_widget_unref (pix);
}

void pixbuf_free(guchar *pixels, gpointer data)
{
    g_free(pixels) ;
    fprintf(stderr, "pixbuf data freed\n") ;
}

int main (int argc, char *argv[])
{

    GdkPixbuf *pixbuf;

    // GTK

    GtkWidget *window;
    GtkWidget* image;

    image = gtk_image_new();

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_window_set_title (GTK_WINDOW (window), "Image Viewer");

    g_signal_connect (window, "destroy", G_CALLBACK (Deinit), NULL);
    g_signal_connect (window, "expose-event",G_CALLBACK (draw_call), NULL);

    g_timeout_add (1000, draw_call, NULL);

    gtk_widget_set_app_paintable(window, TRUE);
    gtk_widget_set_double_buffered(window, FALSE);

    gtk_container_add(GTK_CONTAINER (window), image);

    gtk_widget_show_all (window);

    gtk_main ();

    return 0;
}

```