iTextSharp.text.pdf.Barcode39.CreateDrawingImage C# (CSharp) Метод

CreateDrawingImage() публичный Метод

public CreateDrawingImage ( System foreground, System background ) : System.Drawing.Image
foreground System
background System
Результат System.Drawing.Image
        public override System.Drawing.Image CreateDrawingImage(System.Drawing.Color foreground, System.Drawing.Color background) {
            String bCode = code;
            if (extended)
                bCode = GetCode39Ex(code);
            if (generateChecksum)
                bCode += GetChecksum(bCode);
            int len = bCode.Length + 2;
            int nn = (int)n;
            int fullWidth = len * (6 + 3 * nn) + (len - 1);
            int height = (int)barHeight;
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fullWidth, height);
            byte[] bars = GetBarsCode39(bCode);
            for (int h = 0; h < height; ++h) {
                bool print = true;
                int ptr = 0;
                for (int k = 0; k < bars.Length; ++k) {
                    int w = (bars[k] == 0 ? 1 : nn);
                    System.Drawing.Color c = background;
                    if (print)
                        c = foreground;
                    print = !print;
                    for (int j = 0; j < w; ++j)
                        bmp.SetPixel(ptr++, h, c);
                }
            }
            return bmp;
        }
    }

Usage Example

Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ISeguranca iseguranca = Factory.GetInstance<ISeguranca>();
                if (!iseguranca.VerificarPermissao(((ViverMais.Model.Usuario)Session["Usuario"]).Codigo, "ALTERAR_CARTAO_SUS",Modulo.CARTAO_SUS))
                {
                    ClientScript.RegisterClientScriptBlock(typeof(String), "ok", "<script>alert('Você não tem permissão para acessar essa página. Em caso de dúViverMais, entre em contato.');window.location='../Home.aspx';</script>");
                }
            }

            if (Request.QueryString["codigo"] != null)
            {
                IPaciente ipaciente = Factory.GetInstance<IPaciente>();
                ViverMais.Model.Paciente paciente = ipaciente.BuscarPorCodigo<ViverMais.Model.Paciente>(Request.QueryString["codigo"]);
                IList<CartaoSUS> cartoes = ipaciente.ListarCartoesSUS<ViverMais.Model.CartaoSUS>(paciente.Codigo);
                long result = (from c in cartoes select long.Parse(c.Numero)).Min();
                Barcode39 code39 = new Barcode39();
                code39.Code = result.ToString();
                code39.StartStopText = true;
                code39.GenerateChecksum = false;
                code39.Extended = true;
                System.Drawing.Image img = code39.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                img.Save (ms, System.Drawing.Imaging.ImageFormat.Gif);
                Response.ClearContent();
                Response.ContentType = "image/Gif";
                Response.BinaryWrite(ms.ToArray());
            }
        }
All Usage Examples Of iTextSharp.text.pdf.Barcode39::CreateDrawingImage