Re: [Vala] How to draw on a pixbuf

2016-09-16 Thread Nor Jaidi Tuah
Doing this

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

and then this

> Gdk.cairo_set_source_pixbuf (context, result, 0, 0);
> context.paint ();

can be replaced with the more direct code:

   context.set_source_surface (surface, ...)
   context.paint ();


hand
Nor Jaidi Tuah



PRIVILEGED/CONFIDENTIAL information may be contained in this message. If you 
are neither the addressee (intended recipient) nor an authorised recipient of 
the addressee, and have received this message in error, please destroy this 
message (including attachments) and notify the sender immediately. STRICT 
PROHIBITION: This message, whether in part or in whole, should not be reviewed, 
retained, copied, reused, disclosed, distributed or used for any purpose 
whatsoever. Such unauthorised use may be unlawful and may contain material 
protected by the Official Secrets Act (Cap 153) of the Laws of Brunei 
Darussalam. DISCLAIMER: We/This Department/The Government of Brunei Darussalam, 
accept[s] no responsibility for loss or damage arising from the use of this 
message in any manner whatsoever. Our messages are checked for viruses but we 
do not accept liability for any viruses which may be transmitted in or with 
this message.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] How to draw on a pixbuf

2016-09-16 Thread raum
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


[Vala] How to draw on a pixbuf

2016-09-15 Thread raum
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