[Gtk-sharp-list] Current way of creating a Pixbuf from an RGB Array
Cody Russell
bratsche at gnome.org
Fri Aug 8 12:39:46 EDT 2008
I found some code I used to create Pixbufs from RGB
System.Drawing.Bitmap objects:
public Gdk.Pixbuf CreateFromResource(Bitmap bitmap)
{
BitmapData data = bitmap.LockBits(new Rectangle(0, 0,
bitmap.Width, bitmap.Height,
PixelFormat.Format24bppRgb);
IntPtr scan = data.Scan0;
int size = bitmap.Width * bitmap.Height * 3;
byte[] bdata = new byte[size];
Gdk.Pixbuf pixbuf = null;
unsafe {
byte* p = (byte*)scan;
for(int i = 0; i < size; i++)
bdata[i] = p[i];
}
pixbuf = new Gdk.Pixbuf(bdata, false, 8,
bitmap.Width, bitmap.Height,
data.Stride, null);
bitmap.UnlockBits(data);
return pixbuf;
}
On Thu, 2008-08-07 at 21:55 -0700, egrath wrote:
> Hello,
>
> can someone please tell me what's the current way of getting a Gdk.Pixbuf
> from an byte[] full of RGB Values? I know that there is an overload of the
> Gdk.Pixbuf constructor which would normally accomplish this, but according
> to my tests and Bug ID 362951 it seems to be broken in 2.0 Preview.
>
> I use the following statement:
>
> Gdk.Pixbuf picture = new Gdk.Pixbuf( m_RawData, Gdk.Colorspace.Rgb, false,
> 8, m_RawResolution.Width, m_RawResolution.Height, m_RawResolution.Width * 3,
> null );
>
> and get the following exception:
>
> Unhandled Exception: System.InvalidProgramException: Invalid IL code in
> (wrapper
> native-to-managed) GdkSharp.PixbufDestroyNotifyWrapper:NativeCallback
> (intptr,i
> ntptr): IL_0030: call 0x00000006
>
> Any ideas?
>
> Thanks,
> Egon
>
More information about the Gtk-sharp-list
mailing list