0 Members and 1 Guest are viewing this topic.
Here's My Solution. Had to flip a few things for some odd reason but it works. private SFML.Graphics.Image ToSFMLImage(System.Drawing.Bitmap bmp) { SFML.Graphics.Color[,] sfmlcolorarray = new Color[bmp.Height, bmp.Width]; SFML.Graphics.Image newimage = null; for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { System.Drawing.Color csharpcolor = bmp.GetPixel(x, y); sfmlcolorarray[y,x] = new SFML.Graphics.Color(csharpcolor.R, csharpcolor.G, csharpcolor.B, csharpcolor.A); } } newimage = new SFML.Graphics.Image(sfmlcolorarray); return newimage; } private SFML.Graphics.Texture ToSFMLTexture(System.Drawing.Bitmap bmp) { return new Texture(ToSFMLImage(bmp)); }
Do what you want with this... it only took me 10 minutes Yes the code is messy because I didn't bother to clean it up.using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Windows.Forms;using System.Drawing;using SFML.Window;using SFML.Graphics;using System.IO;namespace WindowsFormsApplication2{ static class Program { static void Main() { RenderWindow wind = new RenderWindow(new VideoMode(500, 500), "Test"); wind.SetVerticalSyncEnabled(true); Texture tx1 = new Texture("LBB.png"); Sprite sp1 = new Sprite(tx1) { Scale = new Vector2f(.4f, .4f) }; var im1 = WindowsFormsApplication2.Properties.Resources.LBB; Texture tx2 = CreateTexture1(im1); Sprite sp2 = new Sprite(tx2) { Scale = new Vector2f(.4f, .4f), Position = new Vector2f (0, 250) }; Texture tx3 = CreateTexture2(im1); Sprite sp3 = new Sprite(tx3) { Scale = new Vector2f(.4f, .4f), Position = new Vector2f (250,250) }; while (wind.IsOpen()) { wind.DispatchEvents(); wind.Clear(SFML.Graphics.Color.White); wind.Draw(sp1); wind.Draw(sp2); wind.Draw(sp3); wind.Display(); } } static Texture CreateTexture1(Bitmap Im) { byte[] array = new byte[Im.Width * Im.Height * 4]; int i = 0; for (int y = 0; y < Im.Height; y++) { for (int x = 0; x < Im.Width; x++) { var px = Im.GetPixel(x, y); array[i] = px.R; array[i + 1] = px.G; array[i + 2] = px.B; array[i + 3] = px.A; i += 4; } } var tx = new Texture((uint)Im.Width, (uint)Im.Height); tx.Update(array); return tx; } static Texture CreateTexture2(Bitmap Im) { MemoryStream stm = new MemoryStream(); Im.Save(stm, System.Drawing.Imaging.ImageFormat.Png); return new Texture(stm); } }}