Am i doing something wrong ??
- From: Omair Zubair <Omair Zubair laitram com>
- To: gtk-list redhat com
- Subject: Am i doing something wrong ??
- Date: Thu, 13 Aug 1998 18:30:37 +0000
Hello all,
I'm trying to write a code that displays an image in the drawing area
from a
buffer and for some reason i cannot get it to work. I'm attaching the
code, can somebody tell me whats wrong with it. I somehow ust cannot the
function
gdk_pixmap_create_from_data()
to work. If i use
gdk_pixmap_create_from_xpm()
the code works fine, but do want to have to write file to the hard drive
I realize this a stupid problem but help me out guys this is my fourth
day working with gtk. i'd really appreciate it.
Thanks in advance.
Omair
#include <gtk/gtk.h>
static GdkPixmap *pixmap;
char pgmoutname[256];
char * imbuf;
int SavePgmImage(char * pgmoutname, char * pimResultImage, int cols, int rows)
{
FILE * pgmoutfile;
pgmoutfile = fopen(pgmoutname,"w");
if (pgmoutfile == NULL)
{
printf("Failed to open image output file!\n");
return(-1);
}
fprintf(pgmoutfile,"P%c\n%d %d\n255\n",'5',cols,rows);
if (rows*cols != fwrite (pimResultImage,sizeof(char),rows*cols,pgmoutfile))
{
printf("Error writing to image output file!");
exit(-1);
}
}
void fakeImage8(char * im) {
char * p, *q;
long g,l = ((long)480+5)*(long)640;
int i,x,y,x1,x2;
/* clear the image */
for (p=im, g=0; g<l; p++,g++)
*p=0;
x=640>>1; x1=x2=x;
for (y=20; y <= (480>>1); y++,x1--,x2++)
{
p= im + x1 + 640 * y;
q= im + x1 + 640 * (480 - y);
#if 1
#define wiggleFactor (1.0 + rand()/(2.0 * RAND_MAX))
for (i=0; i<=4; i++)
{
*(p-4+i) = (i) * 40 * wiggleFactor;
*(q-4+i) = (i) * 40 * wiggleFactor;
*(p+x2-x1+i) = (4-i) * 40 * wiggleFactor;
*(q+x2-x1+i) = (4-i) * 40 * wiggleFactor;
}
#else
*p = 220;
*q = 220;
*(p+x2-x1) = 220;
*(q+x2-x1) = 220;
#endif
}
}
void quit (GtkWidget *widget, gpointer *data)
{
gtk_main_quit();
}
static gint expose_event (GtkWidget *widget, GdkEventExpose *event)
{
GdkBitmap *mask;
GtkStyle *style;
GdkRectangle area;
pixmap= gdk_pixmap_create_from_data(widget->window,imbuf,640,480,8,
&style->fg[GTK_WIDGET_STATE(widget)],
&style->bg[GTK_WIDGET_STATE(widget)]);
gdk_draw_pixmap( widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
pixmap,0,0,0,0,640,480);
gtk_widget_draw(widget,&area);
return FALSE;
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *drawing_area;
GtkWidget *vbox;
gtk_init(&argc, &argv);
imbuf = malloc((unsigned)(640*480+100));
fakeImage8(imbuf);
SavePgmImage("test.pgm",imbuf,640,480);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_name (window, "Test Input");
vbox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox);
gtk_container_add(GTK_CONTAINER(window),vbox);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (quit), NULL);
drawing_area = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 640, 480);
gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT(drawing_area), "expose_event",
(GtkSignalFunc) expose_event, NULL);
gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK);
gtk_widget_show (drawing_area);
gtk_widget_show (window);
gtk_main ();
return 0;
}
begin: vcard
fn: Omair Zubair
n: Zubair;Omair
org: Laitram Corporation
email;internet: omair@laitram.com
x-mozilla-cpt: ;-11616
x-mozilla-html: FALSE
version: 2.1
end: vcard
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]