[Gtk-sharp-list] Gdk.Pixbuf.Pixels property type changed, why?

Vladimir Vukicevic vladimirv@gmail.com
Thu, 3 Jun 2004 21:50:31 -0700


On Fri, 04 Jun 2004 04:33:46 +0200, ivan.guzvinec@telemach.net
<ivan.guzvinec@telemach.net> wrote:
> Hi,
> 
> I upgraded gtk# from 0.16 to 0.93 and I'm getting errors recompiling my project.
> 
> Error message:
> ImageStore.cs(398) error CS0021: Type `System.IntPtr' does not have any indexers
> defined"
> 
> ImageStore.cs@398:
>    ...
>    m_nC = pic.Pixels[ipix] + nStepB;
>    ...
> 
> So I investigated and found that the Gdk.Pixbuf.Pixels property is no longer of
> type byte*, but instead of type IntPtr.
> 
> ./gdk/Pixbuf.custom:
> //
> // the 'Pixels' property
> //
>    [DllImport("libgdk_pixbuf-2.0-0.dll")]
>    static extern IntPtr gdk_pixbuf_get_pixels(IntPtr raw);
> 
>    public unsafe IntPtr Pixels {
>    get {
>        IntPtr ret = gdk_pixbuf_get_pixels (Handle);
>        return ret;
>        }
>    }
> 
> Why did this change?
> How can I now use Gdk.Pixbuf.Pixels property to get/set individual pixels inside
> a Pixbuf? (I need to be able to do "pixbuf.Pixels[index] = color;" too)

It was changed to remove the need to use an unsafe context when
accessing the Pixels property.  If you need to index it, you can just
do:

    byte *pixels = (byte *)pic.Pixels;
...
    m_nC = pixels[ipix] + nstepB;
...

However, I notice that I left the "unsafe" bit there.  Sigh, that'll
get removed asap, as soon as I get approval from mike to do so. :)

    - Vlad