public static void Main(string[] args) { string inputImage = "original_image.png"; /*TO do * { * Console.Write ("Enter path to original image: "); * inputImage = Console.ReadLine (); * } * while(checkFile(inputImage, "original image")); */ string inputFile = "input.txt"; /*TO do * { * Console.Write ("Enter path to file to hide: "); * inputFile = Console.ReadLine (); * } * while(checkFile(inputFile, "file to hide")); */ var inputImageParts = inputImage.Split(new char[] { '\\', '/' }).ToList(); var outputImagePath = inputImageParts.Any() ? string.Join("\\", inputImageParts.Take(inputImageParts.Count - 1)) : null; var outputImage = (string.IsNullOrWhiteSpace(outputImagePath) ? string.Empty : (outputImagePath + "\\")) + "result.png"; IImageWrapper imageWrapper = new SlowImageWrapper(); imageWrapper.LoadFile(inputImage); var ms = new MemoryStream(); using (var fs = new FileStream(inputFile, FileMode.Open)) { fs.CopyTo(ms); ms.Position = 0; } var fileNameParts = inputFile.Split(new char[] { '/', '\\' }).ToList(); var fileModel = new FileModel(ms, fileNameParts.Last()); IFileMuxxer muxxer = new LosslessFileMuxxer(); using (var result = muxxer.Mux(fileModel, imageWrapper)) { result.Save(outputImage); } using (var toDecrypt = new SlowImageWrapper()) { toDecrypt.LoadFile(outputImage); var reversed = muxxer.Demux(toDecrypt); using (var fs = new FileStream("result_" + reversed.FileName, FileMode.Create)) { reversed.FileContents.CopyTo(fs); } } }
public IImageWrapper Mux(FileModel fileModel, IImageWrapper container) { IImageWrapper result = new SlowImageWrapper(); result.InitialiseEmpty(container.Width, container.Height); Pixel[,] dataSet = muxxImageAndFile(fileModel, container); for (var x = 0; x < container.Width; ++x) { for (var y = 0; y < container.Height; ++y) { var pixel = dataSet[x, y]; result.SetRedAtPosition(x, y, pixel.R); result.SetGreenAtPosition(x, y, pixel.G); result.SetBlueAtPosition(x, y, pixel.B); } } return(result); }