Skip to content

Instantly share code, notes, and snippets.

@MasterGordon
Created January 29, 2026 21:43
Show Gist options
  • Select an option

  • Save MasterGordon/ec41e5c1a95fc57fa8ea08b021a08a73 to your computer and use it in GitHub Desktop.

Select an option

Save MasterGordon/ec41e5c1a95fc57fa8ea08b021a08a73 to your computer and use it in GitHub Desktop.
// See https://aka.ms/new-console-template for more information
using System.Numerics;
using AsepriteDotNet.IO;
using AsepriteDotNet.Processors;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using ZeroElectric.Vinculum;
using Image = ZeroElectric.Vinculum.Image;
using Vinculum_Color = ZeroElectric.Vinculum.Color;
unsafe {
var file = AsepriteFileLoader.FromFile(
"/home/gordon/git/dotnet/arcane-agronomist/RaylibSandbox/test-sprite.aseprite");
var width = file.CanvasWidth;
var height = file.CanvasHeight;
var sp = SpriteProcessor.Process(file, frameIndex: 0, true);
var image = new Image<Rgba32>(width, height);
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
// Get pixel color
var pixelColor = sp.Texture.Pixels[y * sp.Texture.Size.Width + x];
// Convert to ARGB format and write to the bitmap
image[x, y] = new Rgba32(pixelColor.R, pixelColor.G, pixelColor.B, pixelColor.A);
}
}
var bmpStream = new MemoryStream();
// Save the bitmap to the memory stream in BMP format
image.SaveAsPng(bmpStream);
// Reset the stream position to the beginning
bmpStream.Seek(0, SeekOrigin.Begin);
// Save to png file
File.WriteAllBytes("test.png", bmpStream.GetBuffer());
var bytes = bmpStream.GetBuffer();
Image rImage;
fixed (byte* ptr = bytes) {
rImage = Raylib.LoadImageFromMemory(".png", ptr, bytes.Length);
}
// Raylib.SetTargetFPS(60);
Raylib.InitWindow(800, 480, "Hello World");
Raylib.SetWindowState(ConfigFlags.FLAG_WINDOW_RESIZABLE);
var rTexture = Raylib.LoadTextureFromImage(rImage);
while (!Raylib.WindowShouldClose()) {
Console.WriteLine("Frame: " + Raylib.GetFrameTime());
Console.WriteLine("FPS: " + Raylib.GetFPS());
Raylib.BeginDrawing();
Raylib.ClearBackground(new Vinculum_Color { a = 255, b = 100, g = 100, r = 0 });
Raylib.DrawText("Hello, world!", 12, 12, 20, new Vinculum_Color { a = 255, b = 255, g = 255, r = 255 });
Raylib.DrawTextureEx(rTexture, new Vector2(20, 20), 0, 2,
new Vinculum_Color { a = 255, b = 255, g = 255, r = 255 });
Raylib.EndDrawing();
}
Raylib.CloseWindow();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment