[Gtk-sharp-list] From Gtk+ to Gtk#
Alexandre Gomes
alexmipego@hotmail.com
Wed, 09 Mar 2005 13:28:17 +0000
Hi,
This is not linear, but I'll try to help you. First of all, C# is 100%
object oriented, so many things appear a little different from the
original API. Yet, object support methods but somethings work even a
little bit more different, for instance most *_get_* and *_set_* become
properties in C# world.
For example, in your code to get the dimensions:
ht=gdk_pixbuf_get_height(pb);
wt=gdk_pixbuf_get_width(pb);
turns into:
ht = yourpixbufferObject.Height;
wt = yourpixbufferObject.Width;
this warps to the ..._get_... and if there was a set it would be:
yourpixbufferObject.Height = ht;
Yet, many things are different, for instance that properties are read-
only, so you can't set them. You must use methods.
Anyway, you should see monodoc references to see the details for the
Gtk# implementations. Mosts things will sound familiar to you.
Now, about the Color of pixels, it looks to me that isn't implemented
yet. The property returns a System.IntPtr or (in C language) a int
pointer. The documentation states that this pointer points to the real
data, so you can use it as you would do C - who knows a copy paste would
work... lol. I've no experience in using C code from C# side, so I can't
tell you for sure if you will not need to use the "unsafe" option in mcs
to work out this pointer.
Anyway, a GTK# guru can tell you better, but I tried to put you in the
right track.
On Wed, 2005-03-09 at 11:30 +0100, amartinez@atc.ugr.es wrote:
> Hello,
> I'd like to know how can I translate this code
> (http://cybernetics.freewebspace.com/gtk/improc/node14.html) from from
> Gtk+ to Gtk#. I paste the code below.
>
> The main question is: how can I set/get the colors from every individual
> pixel from a Pixbuf?
>
> Thanks.
>
> <code>
> void draw_normal_border(GdkPixbuf *pb,int red,int green,int blue)
> {
> int ht,wt;
> int i=0,j=0;
> int flag=0;
> int border=10; //10 pixels wide border.
> int rowstride=0;
> gchar *pixel;
>
> ht=gdk_pixbuf_get_height(pb);
> wt=gdk_pixbuf_get_width(pb);
> pixel=gdk_pixbuf_get_pixels(pb);
> rowstride=gdk_pixbuf_get_rowstride(pb);
>
>
> for(i=0;i<ht;i++)
> for(j=0;j<rowstride;j+=3)
> {
> flag=0;//reset flag every time.
>
> if(i< (border))
> flag=1;
> else if(i > (ht-border))
> flag=1;
> else if(j < (border)*3)
> flag=1;
> else if(j > (wt-border)*3)
> flag=1;
>
>
> if(flag==1)
> {
> pixel[i*rowstride+j+0]=red;
> pixel[i*rowstride+j+1]=green;
> pixel[i*rowstride+j+2]=blue;
> }
> }
> return;
> }
> </code>
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
--
Alexandre Miguel Pedro Gomes,
Portugal