Hello,

I think I've found a solution :)
- create a Surface and get the context of this surface
- draw on the surface
- create a pixbuf from the surface
- copy pixbuf into my drawingarea !

SOURCE CODE :

using Gtk;
using Cairo;

public static int main (string[] args) {
    Cairo.ImageSurface surface;
    Cairo.Context cr;

    surface = new Cairo.ImageSurface (Cairo.Format.RGB24, 100, 100);

    cr = new Cairo.Context (surface);

    cr.paint();
    cr.set_source_rgb (1, 1, 1);
    cr.rectangle (0, 0, 100, 100);
    cr.fill ();

    cr.set_source_rgb (1, 0, 0);
    cr.rectangle (10, 10, 40, 40);
    cr.fill ();
    cr.move_to(0, 0);
    cr.line_to(100, 100);
    cr.stroke();

    Gdk.Pixbuf result= Gdk.pixbuf_get_from_surface(
        surface, 0, 0, 100, 100);

    Gtk.init (ref args);
    var window = new Window();
    window.title = "First GTK+ Program";
    window.border_width = 10;
    window.window_position = WindowPosition.CENTER;
    window.set_default_size (400, 400);
    window.destroy.connect (Gtk.main_quit);

    DrawingArea da = new DrawingArea();

    window.add(da);

    da.draw.connect ((context) => {
        Gdk.cairo_set_source_pixbuf (context, result, 0, 0);
        context.paint ();
            return true;
        });

    window.show_all ();

    Gtk.main ();


    return 0;

}


> Hello everyone,
>
> I want to prepare a picture and paste in a drawingarea, so I thought I
> should draw on a pixbuf, then copy it to my drawingarea....
>
> I've create a drawing area (500x500) and I've tried this code in "on_draw"
> :
>     public bool on_draw(Widget da, Context context) {
> (...)
>       var pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.RGB, false, 8, 100, 100);
>         Surface s = Gdk.cairo_surface_create_from_pixbuf (pixbuf, 1,
> null);
>         Context c = new Context (s);
>         c.move_to(0, 0);
>         c.line_to(50, 50);
>         c.stroke();
>
>         Gdk.cairo_set_source_pixbuf (context, pixbuf, 0, 0);
>
>         context.paint ();
> (...)
>
> But the result is a partially black rectangle with some with points....
>
> Have you some advices ? :)
>
> Thanks.
>
> Regards
>
> Raum
> _______________________________________________
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>

_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to