Ejemplo n.º 1
0
        public static Image GetImageFromXML(PawnUtilities.BarcodeGenerator.BarcodeXML internalXML)
        {
            try
            {
                //converting the base64 string to byte array
                Byte[] imageContent = new Byte[internalXML.Barcode[0].Image.Length];

                //loading it to memory stream and then to image object
                using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(internalXML.Barcode[0].Image)))
                {
                    return(Image.FromStream(ms));
                } //using
            }     //try
            catch (System.Exception ex)
            {
                throw new System.Exception("EGETIMAGEFROMXML-1: " + ex.Message);
            }//catch
        }
Ejemplo n.º 2
0
        }//CheckNumericOnly

        private string GetXML()
        {
            if (EncodedValue == "")
            {
                throw new System.Exception("EGETXML-1: Could not retrieve XML due to the barcode not being encoded first.  Please call Encode first.");
            }
            else
            {
                try
                {
                    using (PawnUtilities.BarcodeGenerator.BarcodeXML xml = new PawnUtilities.BarcodeGenerator.BarcodeXML())
                    {
                        PawnUtilities.BarcodeGenerator.BarcodeXML.BarcodeRow row = xml.Barcode.NewBarcodeRow();
                        row.Type         = EncodedType.ToString();
                        row.RawData      = RawData;
                        row.EncodedValue = EncodedValue;
                        row.EncodingTime = EncodingTime;
                        row.IncludeLabel = IncludeLabel;
                        row.Forecolor    = ColorTranslator.ToHtml(ForeColor);
                        row.Backcolor    = ColorTranslator.ToHtml(BackColor);
                        row.CountryAssigningManufacturingCode = Country_Assigning_Manufacturer_Code;
                        row.ImageWidth  = Width;
                        row.ImageHeight = Height;

                        //get image in base 64
                        using (MemoryStream ms = new MemoryStream())
                        {
                            EncodedImage.Save(ms, getImageFormat(ImageFormat));
                            row.Image = Convert.ToBase64String(ms.ToArray(), Base64FormattingOptions.None);
                        }//using

                        xml.Barcode.AddBarcodeRow(row);

                        StringWriter sw = new StringWriter();
                        xml.WriteXml(sw, XmlWriteMode.WriteSchema);
                        return(sw.ToString());
                    } //using
                }     //try
                catch (System.Exception ex)
                {
                    throw new System.Exception("EGETXML-2: " + ex.Message);
                } //catch
            }     //else
        }