summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Bitmap.cs21
1 files changed, 19 insertions, 2 deletions
diff --git a/Bitmap.cs b/Bitmap.cs
index 7f7b9d6..8a87f7c 100644
--- a/Bitmap.cs
+++ b/Bitmap.cs
@@ -40,6 +40,22 @@ public unsafe class Bitmap
_ => throw new Exception("Image type not supported... How did you get this error??")
};
+ static readonly IntPtr PngPtr = Marshal.StringToHGlobalAnsi(".png");
+ static readonly IntPtr GifPtr = Marshal.StringToHGlobalAnsi(".gif");
+ static readonly IntPtr JpgPtr = Marshal.StringToHGlobalAnsi(".jpg");
+ static readonly IntPtr TgaPtr = Marshal.StringToHGlobalAnsi(".tga");
+ static readonly IntPtr BmpPtr = Marshal.StringToHGlobalAnsi(".bmp");
+
+ static IntPtr ImageTypeToPointer(ImageType type) => type switch
+ {
+ ImageType.PNG => PngPtr,
+ ImageType.GIF => GifPtr,
+ ImageType.JPG => JpgPtr,
+ ImageType.TGA => TgaPtr,
+ ImageType.BMP => BmpPtr,
+ _ => throw new Exception("Image type not supported... How did you get this error??")
+ };
+
public int Width
{
get => img.width;
@@ -59,7 +75,8 @@ public unsafe class Bitmap
public byte[] ToMemory(ImageType imageType = ImageType.PNG)
{
- byte* ptr = Raylib.ExportImageToMemory(img, ImageTypeToString(imageType), out int length);
+ int length;
+ byte* ptr = Raylib.ExportImageToMemory(img, (sbyte*)ImageTypeToPointer(imageType), &length);
byte[] mem = new byte[length];
Marshal.Copy((nint)ptr, mem, 0, length);
return mem;
@@ -69,7 +86,7 @@ public unsafe class Bitmap
{
Image img;
fixed (byte* ptr = &ImageMemory[0])
- img = Raylib.LoadImageFromMemory(ImageTypeToString(imageType), ptr, ImageMemory.Length);
+ img = Raylib.LoadImageFromMemory((sbyte*)ImageTypeToPointer(imageType), ptr, ImageMemory.Length);
return new Bitmap(img);
}