//Разжать изображение, дополнить информацию, вывести результат в Image2 public void decompressImageAndAddInfo(byte[] compressedBytes) { if (imageValues == null) { return; } var t1 = CurrentTime(); float[] restoredImage = ImageUtils.decompressImageBytes( compressedBytes, out int width, out int height, out string colorScheme, out string method, out int blockSize, out string travelMode, out bool crossMerge ); var t2 = CurrentTime(); view.Image2 = ImageUtils.ConvertValuesToImage(restoredImage, colorScheme, width, height); ImageUtils.calculateDifference( view.Image1, view.Image2, colorScheme, out Tuple <float, float, float> MSE, out Tuple <float, float, float> PSNR ); var time = (t2 - t1) / 1000f; view.Info += string.Format( "\nРазжато за {0} секунд\n" + "MSE = {1}\n" + "PSNR = {2}\n", time, MSE, PSNR ); }
// загрузить изображение из файла, разжать его при необходимости, // и записать результат в image и imageValues public void loadImage(string path) { if (path.EndsWith(Constants.CompessedExtension)) { byte[] bytes = File.ReadAllBytes(path); var t1 = CurrentTime(); float[] restoredImage = ImageUtils.decompressImageBytes( bytes, out int width, out int height, out string colorScheme, out string method, out int blockSize, out string travelMode, out bool crossMerge ); var t2 = CurrentTime(); var time = (t2 - t1) / 1000f; image = ImageUtils.ConvertValuesToImage(restoredImage, colorScheme, width, height); view.Info = string.Format("Разжато за {0} секунд", time); view.ColorScheme = colorScheme; view.Method = method; view.BlockSize = blockSize; view.TravelMode = travelMode; view.CrossMerge = crossMerge; } else { image = Image.FromFile(path); } imageValues = null; view.Image2 = view.DefaultImage; ConvertCurrentImageIntoValues(); view.Image1 = image; view.Title = string.Format("{0}: {1}x{2} ({3}КБ)", path, image.Width, image.Height, image.Width * image.Height * 3 / 1000f); }