Hello everyone! I'm fairly new to using gtk and c and I have a question regarding changing the color of pixels. So I have an image file I read it and do some calculations using the pixel data which I access doing this:
Code:
pixbuf = gtk_image_get_pixbuf(img);
n_channels = gdk_pixbuf_get_n_channels(pixbuf);
pixs=gdk_pixbuf_get_pixels(pixbuf);
rowstride=gdk_pixbuf_get_rowstride(pixbuf);
Then I position myself on the image pixel using this
Code:
/*p is also a guchar
x and y are the image coordinates*/
p = pixs + y * rowstride + x * n_channels;
and then I change the color of a pixel using this
Code:
p[0]=50;
p[1]=0;
p[2]=0;
For example, afterwards I just write the modified image to hard drive
Code:
gdk_pixbuf_save(pixbuf,"/.../.../Desktop/image.png","png",NULL,NULL);
The strange thing is that the image appears on my Desktop and the pixels are colored like it should but my program crashes.
If I comment this part out:
Code:
p[0]=50;
p[1]=0;
p[2]=0;
Then the program never crashes.
So my question is, is it fine the way I am coloring the pixels or should I do it another way? Apparently the program doesn't like the way I color the pixels since that's the only part that causes it to crash.
Any tips?