CreateDrawingImage() public method

public CreateDrawingImage ( System foreground, System background ) : System.Drawing.Image
foreground System
background System
return System.Drawing.Image
Ejemplo n.º 1
2
    /// <summary>
    /// this version outputs gif to web page
    /// ProcessRequest is intrinsic function of hppthandler, do not change the name
    /// </summary>
    /// <param name="context"></param>
    public void ProcessRequest(HttpContext context)
    {
        //for a custom httphandler make sure it's referenced in web.config in httpHandlers
        //<add verb="GET" path="*barcode.gif" type="barcode_handler" validate ="false" />
        //
        if(context.Request["code"] != null){

            string _code = wwi_security.DecryptString(context.Request["code"].ToString(),"publiship"); //code to use
            int _wd = 120; //context.Request["wd"] != null ? wwi_func.vint(context.Request["wd"].ToString()) : 120; //width
            int _ht = 30; //context.Request["ht"] != null ? wwi_func.vint(context.Request["ht"].ToString()) : 30; //height

            Barcode128 _bc = new Barcode128();
            _bc.CodeType = Barcode.CODE128;
            _bc.ChecksumText = true;
            _bc.GenerateChecksum = true;
            _bc.Code = _code;

            //draws directly to web page with no code underneath bar
            //System.Drawing.Bitmap _bm = new System.Drawing.Bitmap(_bc.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
            //_bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);

            //draws with actual code underneath bar
            //create bitmap from System.Drawing library, add some height for actual code underneath
            Bitmap _bm = new Bitmap(_wd, _ht + 10);
            //provide this, else the background will be black by default
            Graphics _gr = Graphics.FromImage(_bm);
            
            _gr.PageUnit = GraphicsUnit.Pixel;
            _gr.Clear(Color.White); 
            //draw the barcode
            _gr.DrawImage(_bc.CreateDrawingImage(Color.Black, System.Drawing.Color.White), new Point(0,0));
            //place text underneath - if you want the placement to be dynamic, calculate the point based on size of the image
            System.Drawing.Font _ft = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
            SizeF _sz = _gr.MeasureString(_code, _ft); 
            //position text
            _wd = (_wd - (int)_sz.Width) / 2;
            
            StringFormat _sf = new StringFormat();
            _sf.Alignment = StringAlignment.Center;
            _sf.LineAlignment = StringAlignment.Center;

            _gr.DrawString(_code, _ft, SystemBrushes.WindowText,_wd,_ht, _sf);
            //output as gif to web page,  can also save it to external file
            _bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        }//end if
    }
Ejemplo n.º 2
1
        public Bitmap box(string prodCode, string urun, string renk, string numara, string nakitFiyat, string krediFiyat)
        {
            System.Drawing.Bitmap bmpimg;

            Barcode128 code128 = new Barcode128();
            code128.CodeType = iTextSharp.text.pdf.Barcode.CODE128;
            code128.ChecksumText = true;
            code128.GenerateChecksum = true;
            code128.StartStopText = false;
            code128.Code = prodCode;
            code128.BarHeight = 60;

            bmpimg = new Bitmap(130, 150);

            Graphics bmpgraphics = Graphics.FromImage(bmpimg);
            Pen pen = new Pen(Color.Black, 3.0f);
            System.Drawing.Rectangle rec = new System.Drawing.Rectangle(92, 2, 32, 27);
            bmpgraphics.Clear(Color.White);

            bmpgraphics.DrawRectangle(pen, rec);
            bmpgraphics.DrawString(urun, new System.Drawing.Font("Arial", 9, FontStyle.Bold), SystemBrushes.WindowText, new Point(8, 4));
            bmpgraphics.DrawString(renk, new System.Drawing.Font("Arial", 8, FontStyle.Regular), SystemBrushes.WindowText, new Point(8, 18));
            bmpgraphics.DrawString(numara, new System.Drawing.Font("Arial", 15, FontStyle.Bold), SystemBrushes.WindowText, new Point(95, 5));
            bmpgraphics.DrawImage(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), new Point(10, 40));

            bmpgraphics.DrawString(prodCode, new System.Drawing.Font("Arial", 7, FontStyle.Regular), SystemBrushes.WindowText, new Point(30, 102));
            bmpgraphics.DrawString("Nakit:" + nakitFiyat + " TL", new System.Drawing.Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(15, 114));
            bmpgraphics.DrawString("Kredi:" + krediFiyat + " TL", new System.Drawing.Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(15, 132));
            //pictureBox1.Image = bmpimg;

            return bmpimg;
        }
        // Tuotteen lisäys nappulan koodit
        private void btn_add_prod_Click(object sender, RoutedEventArgs e)
        {
            Random rnd = new Random();                                                                          // Random num generaattori
            string random_barcode = rnd.Next(10000000, 99999999).ToString(); // Tehdään barcode random numerolla

            // Luodaan barcode
               Barcode128 code128 = new Barcode128();
            code128.CodeType = Barcode.CODE128_UCC;
            code128.Code = random_barcode;

            // Generoidaan barcode png image /barcodes hakemistoon
            System.Drawing.Bitmap barcode = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));  // Mustaa valkoiselle
            barcode.Save("barcodes/"+random_barcode+".png");    // Tallennetaan /barcodes hakemistoon

            // Ihan samat SQL Connectionit kun aina.
            string dbConnectionString = @"Data Source=database.db;Version=3;";
            SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString);
            if (tb_name_update.Text != "" && tb_brand_update.Text != "" && tb_qty_update.Text != "")    // Jos nimi, brändi ja määrä kentät EIvät ole tyhjiä niin eteenpäin. (Muuten tulee vähän huono tuotemerkintä.)
            {
                try
                {
                    sqliteCon.Open();
                    string Query = "INSERT INTO products (name, brand, price, qty, desc, barcode) VALUES('" + this.tb_name_update.Text + "','" + this.tb_brand_update.Text + "','" + this.tb_price_update.Text + "','" + this.tb_qty_update.Text + "','" + this.tb_desc_update.Text + "','"+random_barcode+"') ";

                    SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon);
                    createCommand.ExecuteNonQuery();

                    sqliteCon.Close();                                                  // Sinne vaan pusketaan tiedot taas tietokantaan ja näytetään käyttäjälle ilmoitus ja suljetaan db-yhteys.
                    MessageBox.Show("Product added successfully!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                                                                                        // Kun tiedot on uploadattu niin päivitetäänpä samalla vaivalla datagrid niin ei pysyy käyttäjäkin ajan tasalla.
                updateGrid();

            }
        }
 //**********************************************************************************
 //Generar un nuevo codigo de barras
 public Bitmap GenerarCodBarras(string codParaGenerar)
 {
     Barcode128 codigo_barras = new Barcode128();
     codigo_barras.CodeType = Barcode128.CODE128;
     codigo_barras.Code = codParaGenerar;
     codigo_barras.AltText = codParaGenerar;
     codigo_barras.TextAlignment = Barcode128.SHIFT;
     Bitmap codigo_barras_completo = new Bitmap(codigo_barras.CreateDrawingImage(Color.Black, Color.White));
     return codigo_barras_completo;
 }