protected override Document OnLoad(Stream input) { if (input == null || input.Length == 0) { return(null); } var length = input.Length; var bytes = new byte[length]; input.ProperRead(bytes, 0, (int)length); var dec = new WsqDecoder(); using (var bitmap = dec.DecodeGdi(bytes)) { var surface = new Surface(bitmap.Width, bitmap.Height); surface.CopyFromGdipBitmap(bitmap); var layer = new BitmapLayer(surface); var document = new Document(layer.Width, layer.Height); document.Layers.Add(layer); document.DpuUnit = MeasurementUnit.Inch; document.DpuX = (double)bitmap.HorizontalResolution; document.DpuY = (double)bitmap.VerticalResolution; return(document); } }
private byte[] getHuella(byte[] wsq) { byte[] byteArray = new byte[0]; MemoryStream ms = new MemoryStream(wsq); byte[] data = new byte[ms.Length]; ms.Read(data, 0, data.Length); WsqDecoder decoder = new WsqDecoder(); Bitmap bmp = decoder.Decode(data); using (MemoryStream stream = new MemoryStream()) { bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Close(); byteArray = stream.ToArray(); } return(byteArray); }
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); } }