private void UpdateNudValues() { if (rbQuality.Checked) { nudCompressionRatio.Value = (decimal)WsqCodec.QualityToCompressionRatio((int)nudQuality.Value); nudBitrate.Value = (decimal)WsqCodec.CompressionRatioToBitrate((float)nudCompressionRatio.Value); } else if (rbCompressionRatio.Checked) { nudQuality.Value = (decimal)WsqCodec.CompressionRatioToQuality((float)nudCompressionRatio.Value); nudBitrate.Value = (decimal)WsqCodec.CompressionRatioToBitrate((float)nudCompressionRatio.Value); } else if (rbBitrate.Checked) { nudCompressionRatio.Value = (decimal)WsqCodec.BitrateToCompressionRatio((float)nudBitrate.Value); nudQuality.Value = (decimal)WsqCodec.CompressionRatioToQuality((float)nudCompressionRatio.Value); } }
private void saveButton_Click(object sender, EventArgs e) { var path = Path.Combine(Helper.GetImagesPath(), "saved_fp.wsq"); var enc = new WsqEncoder(); var dec = new WsqDecoder(); try { //var info = WsqCodec.GdiImageToImageInfo((Bitmap)inbox.Image); //var bytes = WsqCodec.Encode(info, 100, "This is David!"); enc.Comment = "This is David!"; var bytes = Encode(enc, (Bitmap)inbox.Image); File.WriteAllBytes(path, bytes); // Try to display the wsq image //var outinfo = WsqCodec.Decode(bytes); //if (outinfo != null && !outinfo.IsEmpty) //{ // var wsqbmp = WsqCodec.ImageInfoToGdiImage(outinfo); // outbox.Image = wsqbmp; //} var outinfo = dec.Decode(bytes); var wsqbmp = dec.DecodeGdi(bytes); outbox.Image = wsqbmp; var comments = WsqCodec.GetComments(bytes); outlogbox.AppendText(string.Format("Q = {0}\r\n", nudQuality.Value)); outlogbox.AppendText(string.Format("Cr = {0}\r\n", nudCompressionRatio.Value)); outlogbox.AppendText(string.Format("Br = {0}\r\n", nudBitrate.Value)); outlogbox.AppendText(string.Format("Size (bytes) = {0}\r\n", bytes.Length)); LogInfo(outinfo, comments, outlogbox); outlogbox.AppendText("--------------------------------------------------------\r\n"); outlogbox.Select(outlogbox.Text.Length, 0); outlogbox.ScrollToCaret(); } catch (Exception ex) { MessageBox.Show(this, string.Format("Error: {0}", ex), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LoadWsq(string path) { var dec = new WsqDecoder(); try { var bytes = File.ReadAllBytes(path); var info = dec.Decode(bytes); var bitmap = dec.DecodeGdi(bytes); pbox.Image = bitmap; var comments = WsqCodec.GetComments(bytes); LogInfo(info, comments); logbox.AppendText("--------------------------------------------------------\r\n"); logbox.Select(logbox.Text.Length, 0); logbox.ScrollToCaret(); } catch (Exception ex) { MessageBox.Show(this, string.Format("Error: {0}", ex), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }