public static void INIT() { var R = TermController.RunCommand("fbset", "-i"); Thread.Sleep(100); while (true) { string line = ""; try { line = R.ReadLine(); } catch { throw new MissingFieldException(); } if (line.StartsWith("mode \"")) { string[] info = line.Substring(6).Split(new char[] { 'x' }, StringSplitOptions.RemoveEmptyEntries); info[1].Substring(0, info[1].Length - 1); X = int.Parse(info[0]); Y = int.Parse(info[1]); BufferSize = X * Y; IMG = new LCDIMG() { Buffer = new byte[BufferSize], LineLength = X }; break; } } R.Close(); }
public static void WriteBuffer(LCDIMG img) { if (img.Buffer.Length != BufferSize) { throw new ArgumentOutOfRangeException(); } else { IMG = img; } }
public static void SaveIMG(string path, LCDIMG img) { FileStream FS = new FileStream(path, FileMode.OpenOrCreate); byte[] header = new byte[8]; BitConverter.GetBytes(img.LineLength).CopyTo(header, 0); BitConverter.GetBytes(img.Buffer.Length).CopyTo(header, 4); FS.Write(header, 0, 8); FS.Write(img.Buffer, 0, img.Buffer.Length); FS.Close(); }
/*format Data * 1: X -4byte int32 * 2: BS -4byte int32 * 3: DATA */ public static LCDIMG LoadIMG(string path) { FileStream FS = new FileStream(path, FileMode.Open); byte[] buf = new byte[8]; FS.Read(buf, 0, 8); LCDIMG img = new LCDIMG(); img.LineLength = BitConverter.ToInt32(buf, 0); img.Buffer = new byte[BitConverter.ToInt32(buf, 4)]; FS.Read(img.Buffer, 0, img.Buffer.Length); FS.Close(); return(img); }