LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-27-2005, 11:09 AM   #1
TTL_2
LQ Newbie
 
Registered: Jul 2004
Location: Germany
Posts: 24

Rep: Reputation: 15
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?
 
Old 04-27-2005, 05:25 PM   #2
TTL_2
LQ Newbie
 
Registered: Jul 2004
Location: Germany
Posts: 24

Original Poster
Rep: Reputation: 15
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.
 
Old 01-14-2013, 01:48 AM   #3
fhleung
Member
 
Registered: Aug 2004
Distribution: Fedora, Debian
Posts: 327

Rep: Reputation: 30
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

Last edited by fhleung; 01-19-2013 at 10:11 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GIMP - 16 bit/color (48 bit/pixel) Maxxum9 Linux - Software 1 01-03-2005 08:43 PM
how to get window from gdk to gtk? SciYro Programming 1 08-03-2004 09:01 PM
get-background-color in GTK+-2.0 fromzj Programming 0 04-04-2004 03:46 AM
gtk , gdk ????? varunk123456 Linux - Software 7 04-03-2004 01:22 PM
Unix / Linux gtk/gdk compataibilty acid_kewpie Linux - General 1 10-09-2001 05:39 AM


All times are GMT -5. The time now is 04:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration