Skip to content

Instantly share code, notes, and snippets.

@OMGasm
Created August 13, 2018 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OMGasm/31ff8b2c7796c1621ee4f0d1bc98a709 to your computer and use it in GitHub Desktop.
Save OMGasm/31ff8b2c7796c1621ee4f0d1bc98a709 to your computer and use it in GitHub Desktop.
bullshit image converter to 0bpp because i was bored
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
namespace whythefuckwouldyouusethis
{
public class BSImage
{
public static Image Decode(byte[] bs)
{
if (bs?.Length != 12) return null;
int w = BitConverter.ToInt32(bs, 0);
int h = BitConverter.ToInt32(bs, 4);
Color c = Color.FromArgb(bs[8], bs[9], bs[10], bs[11]);
Bitmap img = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
img.Palette.Entries[0] = c;
return img;
}
public static byte[] Encode(Image im)
{
int w = im.Width;
int h = im.Height;
Color c = im.Palette.Entries[0];
return BitConverter.GetBytes(w)
.Concat(BitConverter.GetBytes(h))
.Concat(new byte[] { c.R, c.G, c.B, c.A })
.ToArray();
}
public static void Save(string loc, Image im)
{
File.WriteAllBytes(loc, Encode(im));
}
public static Image Load(string loc)
{
return Decode(File.ReadAllBytes(loc));
}
}
}
@OMGasm
Copy link
Author

OMGasm commented Aug 13, 2018

(i haven't even tested it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment