[Gtk-sharp-list] Setting the RGB value of a specific pixel of a Pixbuf in Gtk#

Frank Gutierrez Domínguez f.gutierrez at lab.matcom.uh.cu
Mon Apr 25 11:34:51 EDT 2011

Hello everyone!

I need to implement a method to dynamically build a Pixbuf from a Stream
(where the data is stored in a rare format, not compliant with any of the
standard image formats), so I need to specify the pixel values one by one.
In fact, I’m migrating a project originally made with System.Drawing and
Windows.Forms, but I need to absolutely avoid the use of these namespaces.
So, the original version uses a Bitmap and its method SetPixel() like this:


public MyMethod(BinaryReader br)


              Icon = new Bitmap(br.ReadInt32(), br.ReadInt32());

              for (int y = 0; y < Icon.Height; y++)

                     for (int x = 0; x < Icon.Width; x++)


                                  Color c = Color.FromArgb(br.ReadByte(),
br.ReadByte(), br.ReadByte(), br.ReadByte());

                                  Icon.SetPixel((x, y, c);




I’m substituting every instance of System.Drawing.Bitmap for Gdk.Pixbuf in
my code, but the later one doesn’t have any method like SetPixel, so I don’t
know how to do this. In the official Mono documentation the only thing like
this I found is the Pixels property, but this returns a IntPtr and I don’t
know how to use it to access a specific pixel within the Pixbuf. 

Can anybody help???


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20110425/b285a2e0/attachment-0001.html 

More information about the Gtk-sharp-list mailing list