public static Fitmap LoadFromFile(string fileName) { Fitmap f = new Fitmap(); FileStream fStream = new FileStream(fileName, FileMode.Open); byte[] headerSize = new byte[2]; fStream.Read(headerSize, 0, 2); f.headerSize = BitConverter.ToUInt16(headerSize, 0); if (f.headerSize == versionZeroHeaderSize) { f.ReadHeaderV0(fStream); f.fitmapVersion = 0; f.compressionType = 0; } else { f.ReadHeaderInfo(fStream); f.ReadHeaderBasedOnVersion(fStream); } int cLength = f.width * f.height; int sampledLength = f.GetSampledRowLength() * f.height; f.cBytes = new byte[cLength]; f.mBytes = new byte[sampledLength]; f.yBytes = new byte[sampledLength]; FitmapCompression.Read(f.compressionType, f.cBytes, f.mBytes, f.yBytes, fStream); fStream.Close(); return(f); }
public void SaveToFile(string fileName) { if (File.Exists(fileName)) { File.Delete(fileName); } FileStream fStream = new FileStream(fileName, FileMode.OpenOrCreate); /*byte[] header = new byte[headerSize]; * byte[] tmp = BitConverter.GetBytes(headerSize);*/ fStream.Write(BitConverter.GetBytes(headerSize), 0, 2); fStream.Write(BitConverter.GetBytes(fullSize), 0, 2); fStream.Write(BitConverter.GetBytes(fitmapVersion), 0, 1); fStream.Write(BitConverter.GetBytes(compressionType), 0, 1); fStream.Write(BitConverter.GetBytes(width), 0, 2); fStream.Write(BitConverter.GetBytes(height), 0, 2); FitmapCompression.Write(compressionType, cBytes, mBytes, yBytes, fStream); fStream.Close(); }