From c87c0d7d259adb19514e18b74d3195d60a535ac1 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Thu, 1 Jul 2010 18:23:14 +0000 Subject: [PATCH] FS#161 - Added a Image(uint, uint, byte[]) constructor in the Image class (in SFML.Net) git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1528 4e206d99-4929-0410-ac5d-dfc041789085 --- dotnet/src/Graphics/Image.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/dotnet/src/Graphics/Image.cs b/dotnet/src/Graphics/Image.cs index fee23090..202f858c 100644 --- a/dotnet/src/Graphics/Image.cs +++ b/dotnet/src/Graphics/Image.cs @@ -112,7 +112,31 @@ namespace SFML { uint Width = (uint)pixels.GetLength(0); uint Height = (uint)pixels.GetLength(1); - SetThis(sfImage_CreateFromPixels(Width, Height, PixelsPtr)); + SetThis(sfImage_CreateFromPixels(Width, Height, (byte*)PixelsPtr)); + } + } + + if (This == IntPtr.Zero) + throw new LoadingFailedException("image"); + } + + //////////////////////////////////////////////////////////// + /// + /// Construct the image directly from an array of pixels + /// + /// Image width + /// Image height + /// array containing the pixels + /// + //////////////////////////////////////////////////////////// + public Image(uint width, uint height, byte[] pixels) : + base(IntPtr.Zero) + { + unsafe + { + fixed (byte* PixelsPtr = pixels) + { + SetThis(sfImage_CreateFromPixels(width, height, PixelsPtr)); } } @@ -390,7 +414,7 @@ namespace SFML static extern IntPtr sfImage_CreateFromColor(uint Width, uint Height, Color Col); [DllImport("csfml-graphics", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - unsafe static extern IntPtr sfImage_CreateFromPixels(uint Width, uint Height, Color* Pixels); + unsafe static extern IntPtr sfImage_CreateFromPixels(uint Width, uint Height, byte* Pixels); [DllImport("csfml-graphics", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] static extern IntPtr sfImage_CreateFromFile(string Filename);