Advertisement
Ham62

Untitled

Jan 20th, 2017
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1.         static byte[] FILE_MAGIC = { //0x54474658
  2.             (byte)'T', (byte)'G', (byte)'F', (byte)'X'
  3.         };        
  4.  
  5.         public static void SaveGFX(TxtGFX Image, string Filename)
  6.         {
  7.  
  8.             Stream stream = new FileStream(Filename, FileMode.Create, FileAccess.Write);
  9.             BinaryWriter Output = new BinaryWriter(stream);
  10.             // Write header file
  11.             Output.Write(FILE_MAGIC);
  12.             Output.Write(Image.Width);
  13.             Output.Write(Image.Height);
  14.             // Write actual image
  15.             Output.Write(PtrToByteArray((byte*)Image.Image, Image.Size));
  16.             stream.Close();
  17.         }
  18.  
  19.         private static byte[] PtrToByteArray(byte* DataPointer, short Size)
  20.         {
  21.             byte[] OutArray = new byte[Size];
  22.             for (int X = 0; X < Size; X++)
  23.             {
  24.                 OutArray[X] = DataPointer[X];
  25.             }
  26.             return OutArray;
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement