Re: [newbie] How to plot to drawing_area
- From: "Individual . ." <individual mi cl>
- To: gtk-app-devel-list gnome org
- Subject: Re: [newbie] How to plot to drawing_area
- Date: Mon, 3 Feb 2003 13:54:37 -0300
On Sunday, February 2, 2003, at 04:04 PM, Havoc Pennington wrote:
On Sat, Feb 01, 2003 at 06:09:48PM -0300, Individual . . wrote:
I decided it would be great if I could learn how to plot an image to a
window, pixel by pixel. Getting the image is no problem at all, since
I wrote a simple c++ class that uses libpng
(<http://pngwriter.sourceforge.net/>).
The plotting part is what is holding me up.
Well, if you were just trying to get work done instead of trying to
learn, you could do:
error = NULL;
pixbuf = gdk_pixbuf_new_from_file ("foo.png", &error);
if (error != NULL)
{
g_printerr ("error loading image: %s\n", error->message);
g_error_free (error);
exit (1);
}
image = gtk_image_new_from_pixbuf (pixbuf);
Ah! Yes, I agree with you: that gets the job done but I don't learn
much. And after having put so much time and effort into my png-plotting
class, I'd like to use it! So, on to the next question:
Even with a drawing area a pixbuf remains the way to go, but to draw
point by point you would do:
GdkColor color;
gc = gdk_gc_new (drawing_area->window);
gdk_color_parse (&color, "blue"); /* or set
color.red/color.blue/color.green */
gdk_gc_set_rgb_fg_color (gc, &color);
gdk_draw_point (drawing_area->window, gc, x, y);
Thank you! That is what I was looking for, I believe. From my quick
glance at how to program in X11, the function calls in gdk/xlib seem
quite similar.
But this is far too slow for drawing a whole image.
Yes, it most certainly is! I followed this approach in a plain X11
window, no Gtk, and it was SLOW!
I then decided that if I was going to get anything done, I was going to
have to
a) get the RGB image data from the image I want to draw with my
interface functions for reading the png
b) put this into an array in the order that Gtk/xlib wants it (what I'm
stuck on right now, though unrelated to this post)
c) Display this image with the tools that xlib or Gtk give me.
One thing I have been thinking over, and I'm sort of thinking aloud
here, I haven't tried to find out about this yet, I wonder if it is
possible to let my program continue its work once the window has been
displayed? Because Gtk at least also has to have an event loop to catch
the window/button events, and an X11 tutorial that I saw just used the
old while(1){ ... } loop. So my program sort of stops there. I know
that one might use fork(), which I still have to learn how to use, but
I wonder if this is available on all systems that support X11.
Anyway, that was just me thinking aloud.
Thanks for the info.
Paul
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]