public static BarcodeView CreateBarcode(string Filename) { using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) { tx.Create(); // assemble the barcode URL BarcodeData data = new BarcodeData() { Barcode = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Home/ViewDocument?document=" + Filename }; // load the barcode template tx.Load(HttpContext.Current.Server.MapPath("~/App_Data/barcode.tx"), TXTextControl.StreamType.InternalUnicodeFormat); MailMerge mm = new MailMerge() { TextComponent = tx }; // merge the barcode mm.MergeObject(data); BarcodeView view = new BarcodeView() { Url = data.Barcode }; // create an return the barcode image foreach (TXTextControl.DataVisualization.BarcodeFrame barcode in tx.Barcodes) { byte[] imageArray; MemoryStream ms = new MemoryStream(); ((TXTextControl.Barcode.TXBarcodeControl)barcode.Barcode).SaveImage( ms, System.Drawing.Imaging.ImageFormat.Png); imageArray = new byte[ms.Length]; ms.Seek(0, System.IO.SeekOrigin.Begin); ms.Read(imageArray, 0, (int)ms.Length); view.Image = "data:image/png;base64," + Convert.ToBase64String(imageArray); return(view); } return(null); } }
private void ShowPrintBarcodePreview(object sender, RoutedEventArgs e) { Device d = (Device)this.dg_DevicesList.SelectedItem; System.Drawing.Image img = barcodeStickerController.GenerateSticker(d); BarcodeView bcv = new BarcodeView(this, barcodeStickerController.ConvertToBitmapImage(img), d.Name); if (bcv.ShowDialog() == true) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FileName = d.Name; saveFileDialog.DefaultExt = ".jpg"; saveFileDialog.Filter = "Images|*.png;*.bmp;*.jpg"; if (saveFileDialog.ShowDialog() == true) { img.Save(saveFileDialog.FileName); } } }