Not sure if it is the code I'm using or SFML but whatever the case something has imploded. Managed to get it to a point that the only issue left is color not wanting to play nice and stay the same. Worst case though is the image doesn't show or is turned into a line.
Here's the current coding from the SFML images up above.
Image image
= new Image
((uint)TestImages
.TestShip.Width,
(uint)TestImages
.TestShip.Height,
GetRGBValues
(new System.Drawing.Bitmap(TestImages
.TestShip))); Image image2
= new Image
((uint)TestImages
.ClosedGridHall.Width,
(uint)TestImages
.ClosedGridHall.Height,
GetRGBValues
(new System.Drawing.Bitmap(TestImages
.ClosedGridHall))); Image image3
= new Image
((uint)TestImages
.TestShip.Width,
(uint)TestImages
.TestShip.Height,
MarshalImageToByteArray
(new System.Drawing.Bitmap(TestImages
.TestShip))); Sprite exsprite
= new Sprite
(new Texture
(image
)); Sprite exsprite2
= new Sprite
(new Texture
(image2
)); Sprite exsprite3
= new Sprite
(new Texture
(image3
)); Commented out the one that doesn't work for what I'm doing. Now I'm down to 3 the commented out one doesn't work with images stored as resource files.
//http://stackoverflow.com/questions/7350679/convert-a-bitmap-into-a-byte-array-in-c private static byte[] ImageToByteArray
(System.Drawing.Image resourceimage
) { System.Drawing.ImageConverter imgcon
= new System.Drawing.ImageConverter(); return (byte[])imgcon
.ConvertTo(resourceimage,
typeof(byte[])); } // Yes Straight up C&P from here: //http://social.msdn.microsoft.com/Forums/vstudio/en-US/47c5a003-1d26-4213-9370-fba3aa170c21/fastest-method-to-convert-bitmap-object-to-byte-array?forum=csharpgeneral // A Case of either use full quantified names for SFML or C#. >.> private static byte[] GetRGBValues
(System.Drawing.Bitmap bmp
) { // Lock the bitmap's bits. System.Drawing.Rectangle rect
= new System.Drawing.Rectangle(0,
0, bmp
.Width, bmp
.Height); System.Drawing.Imaging.BitmapData bmpData
= bmp
.LockBits(rect,
System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp
.PixelFormat); // Get the address of the first line. IntPtr ptr
= bmpData
.Scan0; // Declare an array to hold the bytes of the bitmap. int bytes
= bmpData
.Stride * bmp
.Height; byte[] rgbValues
= new byte[bytes
]; // Copy the RGB values into the array. System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues,
0, bytes
); bmp
.UnlockBits(bmpData
); return rgbValues
; } //http://www.sitepoint.com/forums/showthread.php?223894-Bitmap-to-byte-array-in-C /*private static byte[] StreamImageToByteArray(System.Drawing.Image resourceimage)
{
MemoryStream stream = new MemoryStream();
resourceimage.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);
//Byte[] bytes =
if (stream != null)
{
stream.Close();
}
return stream.ToArray();
}*/ //http://stackoverflow.com/questions/13602281/converting-bitmap-pixels-as-byte-array-fails private static byte[] MarshalImageToByteArray
(System.Drawing.Bitmap bmp
) { // Lock the bitmap's bits. System.Drawing.Rectangle rect
= new System.Drawing.Rectangle(0,
0, bmp
.Width, bmp
.Height); System.Drawing.Imaging.BitmapData bmpData
= bmp
.LockBits(rect,
System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp
.PixelFormat); // Get the address of the first line. IntPtr ptr
= bmpData
.Scan0; // Declare an array to hold the bytes of the bitmap. int bytes
= Math
.Abs(bmpData
.Stride) * bmp
.Height; byte[] rgbValues
= new byte[bytes
]; // Copy the RGB values into the array. System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues,
0, bytes
); bmp
.UnlockBits(bmpData
); return rgbValues
; } Here's an image of the several errors. >.>
Top two are fine but the image color is off. The last one on the left is distorted to heck and back. The one on the right is loaded from file normally. I Have no idea where I'm messing up.