Пример #1
0
        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);
            }
        }
Пример #2
0
 private byte[] Encode(WsqEncoder enc, Bitmap image)
 {
     if (rbQuality.Checked)
     {
         return(enc.EncodeQualityGdi(image, (int)nudQuality.Value));
     }
     else if (rbCompressionRatio.Checked)
     {
         return(enc.EncodeCompressionRatioGdi(image, (int)nudCompressionRatio.Value));
     }
     else if (rbBitrate.Checked)
     {
         return(enc.EncodeGdi(image, (float)nudBitrate.Value));
     }
     else
     {
         throw new Exception("???");
     }
 }
Пример #3
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            var quality = (int)token.GetProperty(PropertyNames.Quality).Value;
            var comment = (string)token.GetProperty(PropertyNames.Comment).Value;

            using (var args = new RenderArgs(scratchSurface))
                input.Render(args, false);

            var enc = new WsqEncoder();

            byte[] bytes = null;
            using (var bitmap = scratchSurface.CreateAliasedBitmap())
            {
                SetResolution(bitmap, input);
                enc.Comment = comment;
                bytes       = enc.EncodeQualityGdi(bitmap, quality);
            }

            if (bytes != null)
            {
                output.Write(bytes, 0, (int)bytes.Length);
            }
        }