private void Decompress_Click(object sender, EventArgs e) { Decompress.Enabled = false; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Data files (*.dat)|*.dat"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { FilePath = openFileDialog1.FileName.Remove((openFileDialog1.FileName.Length - 4), 4); FileStream rs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read); Huffman_Tree tree = new Huffman_Tree(); tree.FrequencyList = (List <Tuple <Dictionary <int, uint>, BitArray> >)formatter.Deserialize(rs); tree.BuildTree(); List <bool> st = new List <bool>(); tree.Encode(tree.Rroot, st, 'R'); st = new List <bool>(); tree.Encode(tree.Groot, st, 'G'); st = new List <bool>(); tree.Encode(tree.Broot, st, 'B'); img = tree.Decompress(); pictureBox2.Image = img; txtWidth.Text = tree.FrequencyList[0].Item1[-100].ToString(); txtHeight.Text = tree.FrequencyList[0].Item1[-101].ToString(); TAP.Text = tree.FrequencyList[0].Item1[-102].ToString(); SEED.Text = tree.FrequencyList[0].Item1[-103].ToString(); rs.Close(); img.Save(FilePath + "new.bmp"); MessageBox.Show("Decompressed Image has been Saved.", "Decompression Sucessful", MessageBoxButtons.OK); } Decompress.Enabled = true; }
private void Compression_Click(object sender, EventArgs e) { Compression.Enabled = false; Huffman_Tree tree = new Huffman_Tree(img); tree.BuildTree(); List <bool> st = new List <bool>(); tree.Encode(tree.Rroot, st, 'R'); st = new List <bool>(); tree.Encode(tree.Groot, st, 'G'); st = new List <bool>(); tree.Encode(tree.Broot, st, 'B'); CompressionOutput(tree, FilePath); tree.Compress(img, FilePath); FileStream fs = new FileStream(FilePath + ".dat", FileMode.Create, FileAccess.Write); tree.FrequencyList[0].Item1.Add(-102, UInt32.Parse(TAP.Text)); tree.FrequencyList[0].Item1.Add(-103, UInt32.Parse(SEED.Text)); formatter.Serialize(fs, tree.FrequencyList); fs.Close(); Compression.Enabled = true; MessageBox.Show("Compressed Image has been Saved.", "Compression Sucessful", MessageBoxButtons.OK); }