// [omeg] added, pixelData are in RGBA format public override void LoadTextureRaw(Texture texture, byte[] pixelData) { if (null == texture) { return; } Debug.Print("LoadTextureRaw: {0}", texture.RendererData); if (texture.RendererData != null) { FreeTexture(texture); } SFMLTexture sfTexture; try { var img = new Image((uint)texture.Width, (uint)texture.Height, pixelData); // SFML Image sfTexture = new SFMLTexture(img); sfTexture.Smooth = true; img.Dispose(); } catch (LoadingFailedException) { Debug.Print("LoadTextureRaw: failed"); texture.Failed = true; return; } texture.RendererData = sfTexture; texture.Failed = false; }
public static byte[] ToBytes(Texture image) { if (image == null) { throw new ArgumentNullException("image"); } SFML.Graphics.Image im = image.CopyToImage(); byte[] pixels = im.Pixels; im.Dispose(); return(pixels); }
private void btnSplit_Click(object sender, EventArgs e) { if (Resource != null) { btnSplit.Visible = false; if (!Directory.Exists(txtOutputPath.Text)) { Directory.CreateDirectory(txtOutputPath.Text); } var srcExt = txtFile.Text.Substring( txtFile.Text.LastIndexOf(".") + 1); var srcName = txtFile.Text.Substring( txtFile.Text.LastIndexOf(Path.DirectorySeparatorChar) + 1).Replace("." + srcExt, string.Empty); var cols = ((int)numericX.Value >= 1) ? (int)numericX.Value : 1; var rows = ((int)numericY.Value >= 1) ? (int)numericY.Value : 1; var width = (int)Resource.Image.Size.X / cols; var height = (int)Resource.Image.Size.Y / rows; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { var destName = txtOutputFormat.Text.Replace( "%f", srcName).Replace( "%ext", srcExt).Replace( "%r", r.ToString()).Replace( "%c", c.ToString()).Replace( "%t", ((r * cols) + c).ToString()); Image image = new Image((uint)width, (uint)height); image.Copy(Resource.Image, 0, 0, new IntRect(c * width, r * height, width, height)); image.SaveToFile(txtOutputPath.Text + destName); image?.Dispose(); image = null; Application.DoEvents(); } } btnSplit.Visible = true; } txtFile.Focus(); }
public static Bitmap BitmapFromTexture(Texture tex) { if (tex == null) { throw new ArgumentNullException("tex"); } SFML.Graphics.Image im = tex.CopyToImage(); Bitmap bitmap = new Bitmap((int)im.Size.X, (int)im.Size.Y); for (uint x = 0; x < im.Size.X; x++) { for (uint y = 0; y < im.Size.Y; y++) { SFML.Graphics.Color c = im.GetPixel(x, y); bitmap.SetPixel((int)x, (int)y, System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B)); } } im.Dispose(); return(bitmap); }
// [omeg] added, pixelData are in RGBA format public override void LoadTextureRaw(Texture texture, byte[] pixelData) { if (null == texture) return; Debug.Print("LoadTextureRaw: {0}", texture.RendererData); if (texture.RendererData != null) FreeTexture(texture); SFMLTexture sfTexture; try { var img = new Image((uint)texture.Width, (uint)texture.Height, pixelData); // SFML Image sfTexture = new SFMLTexture(img); sfTexture.Smooth = true; img.Dispose(); } catch (LoadingFailedException) { Debug.Print("LoadTextureRaw: failed"); texture.Failed = true; return; } texture.RendererData = sfTexture; texture.Failed = false; }