[Mono-bugs] [Bug 362951] New: GC moves data of Gdk. Pixbuf when creating it with RGB buffer

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Feb 19 10:21:53 EST 2008


           Summary: GC moves data of Gdk.Pixbuf when creating it with RGB
           Product: gtk#
           Version: 2.x
          Platform: x86
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: gtk-sharp
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: rothflorian at gmx.de
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development

I have a byte[] containing the RGB (or RGBA) data of an image. I use this
byte[] with the Gdk.Pixbuf(byte[], bool, int, int, int, int,
PixbufDestroyNotify) ctor to create an instance. This works fine for some time.
But when the GC moves the byte[] the Pixbuf does not recognize this and still
displays the same memory area.  So when the Pixbuf is drawn you only see "crap"
or a part of the orginal image that is still in the pointed memory.

Here is my code with which occures this problem:

public static Gdk.Pixbuf ConvertToPixbuf(System.Drawing.Bitmap bmp)
            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
            BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly,

            IntPtr ptr = bmpData.Scan0;

            //We have an alpha channel?
            bool alpha = Bitmap.IsAlphaPixelFormat(bmp.PixelFormat);

            int bytesPerPixel = Bitmap.GetPixelFormatSize(bmp.PixelFormat) / 8;
            int bytes = bmp.Width * bmp.Height * bytesPerPixel;
            byte[] rgbValues = new byte[bytes];

            // Copy the RGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0,

            // Unlock the bits.

            Gdk.Pixbuf buf = new Gdk.Pixbuf(rgbValues, alpha, 8, bmp.Width,
bmp.Height, bmpData.Stride, null);

            return buf; 

Well, I don't think that the copying of the byte data from the IntPtr causes
the problem, because I also tried copying the resulting byte[] byte per byte
into a new array.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list