LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GTK/GDK 1.2 GdkPixmap: Set a pixel with a color (https://www.linuxquestions.org/questions/programming-9/gtk-gdk-1-2-gdkpixmap-set-a-pixel-with-a-color-317721/)

TTL_2 04-27-2005 11:09 AM

GTK/GDK 1.2 GdkPixmap: Set a pixel with a color
 
Hello,
based on
http://www.gtk.org/tutorial1.2/gtk_tut-30.html#ss30.3
I copied part of the code (I gave up to fully understand the code after a few hours) in a program written by me. I get so far to write a procedure which sets on wished x,y coordinates a black point. Responsible for placing a black point is a modified version of the draw_brush() procedure from the example. But I want to set a pixel in any color, not just a black one. I did not found out how to do this. I think it has something to do with widget->style->black_gc. Unfortunately I did not found out how to modify black_gc.
In Delphi I would simply write canvas.pixels[x,y] := $7f0000; to set the pixel on the position x,y to a medium red. I did not figured out how to do similar things with gtk.
Could anyone please help me?

TTL_2 04-27-2005 05:25 PM

I have a solution
 
After one day of searching, I have now a solution for my problem:) :

static void draw_point( GtkWidget *widget, gdouble x, gdouble y, long color) {
GdkColor colors[1];
GdkGC *color_gc = gdk_gc_new (widget->window);
if (pixmap1 != NULL) {
GdkRectangle update_rect;
update_rect.x = x;
update_rect.y = y;
update_rect.width = 1;
update_rect.height = 1;
colors[0].red = (color>>16&0xff)*256;
colors[0].green = (color>>8&0xff)*256;
colors[0].blue = (color>>0&0xff)*256;
gdk_colormap_alloc_color (gdk_colormap_get_system(), &colors[0], FALSE, TRUE);
gdk_gc_set_foreground (color_gc, colors);
gdk_draw_point(pixmap1, color_gc, x, y);
gtk_widget_draw (widget, &update_rect);
} else {
printf("draw_point: Error, pixmap1 not defined\n");
}
}
I do not understand everything, especialy why GdkColor colors[1]; needs to be an array (It has only one element), but it is working now. One day to figure out how to set a pixel on the drawing interface black and an other to find out how to set a pixel to wished color. How efficient :(
I hope that I will understand the code better tomorrow.

fhleung 01-14-2013 01:48 AM

If I would like to change pixel / canvas of imageS

This Linux program can help?

PhotoShop CS2 now FREE!
http://www.adobe.com/downloads/cs2_downloads/index.html


All times are GMT -5. The time now is 03:58 AM.