Advertisement
Ham62

Save Console Text Graphics

Jan 20th, 2017
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1.      unsafe public struct TxtGFX
  2.     {
  3.         public short Size;
  4.         public short Width;
  5.         public short Height;
  6.         public ushort* Image;
  7.     }
  8.  
  9.     [StructLayout(LayoutKind.Sequential, Pack=1)]
  10.     unsafe struct TxtGFXHeader
  11.     {
  12.         public int Magic;
  13.         public short Width;
  14.         public short Height;
  15.     }
  16.  
  17.      public static void SaveGFX(TxtGFX Image, string Filename)
  18.         {
  19.             TxtGFXHeader Header;
  20.             Header.Magic = FILE_MAGIC;
  21.             Header.Width = Image.Width;
  22.             Header.Height = Image.Height;
  23.  
  24.             // Write file header
  25.             IFormatter formatter = new BinaryFormatter();
  26.             Stream stream = new FileStream(Filename, FileMode.Create, FileAccess.Write);
  27.             formatter.Serialize(stream, Header);
  28.             stream.Close();
  29.             // Write actual image
  30.             UnmanagedMemoryStream writeStream = new UnmanagedMemoryStream((byte*)Image.Image, Image.Width * Image.Height * sizeof(ushort), Image.Width * Image.Height * sizeof(ushort), FileAccess.Write);
  31.             byte[] nullArray = new byte[1];
  32.             writeStream.Write(nullArray, 0, Image.Size);
  33.             writeStream.Close();
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement