¿Cómo Agregar código del producto y nombre del producto al código de barra en un PictureBox1

ELIRDFUL 185 Reputation points
2023-09-30T12:33:27.0766667+00:00

Buenas colegas

Importando las librerías de: iTextSharp y utilizando PictureBox1, genero el Código de barra de un producto:

El Código, que genera el Código de barra es:

Dim bcode As New Barcode128
        bcode.BarHeight = 50
        bcode.Code = txtCodigoProducto.Text
        bcode.GenerateChecksum = True
        bcode.CodeType = Barcode.CODE128
        Try
            Dim bm As New Bitmap(bcode.CreateDrawingImage(Color.Black, Color.White))
            Dim img As Image
            img = New Bitmap(bm.Width, bm.Height)
            Dim g As Graphics = Graphics.FromImage(img)
            g.FillRectangle(New SolidBrush(Color.White), 0, 0, bm.Width, bm.Height)
            g.DrawImage(bm, 0, 0)
            PictureBox1.Image = img
        Catch ex As Exception
            MsgBox("No se pudo generar el codigo de barrra")
        End Try

el código de arriba funciona nítido sale así: 

01

ahora bien, cual es el problema
que solo me sale el código de barra y quiero que debajo de la imagen del código de barra me salga el código del producto y si es posible arriba salga el nombre del producto

me gustaría que el código de barra salga así: 

02

un millón de gracias por adelantado, cuento con sus orientaciones.... 

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
{count} votes

Accepted answer
  1. KOZ6.0 6,300 Reputation points
    2023-10-01T23:17:09.7766667+00:00

    ここは英語のコンテンツです。貴方がスペイン語で書き込むなら、私は日本語で書き込みます。 バーコードの縦横2倍の大きさのビットマップを作って製品コードと製品名を適当な位置に描いてみました。 位置や大きさは貴方が調整してください。

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        Dim bcode As New Barcode128 With {
            .BarHeight = 50,
            .Code = txtCodigoProducto.Text,
            .GenerateChecksum = True,
            .CodeType = Barcode.CODE128
        }
    
        Using bm = bcode.CreateDrawingImage(Color.Black, Color.White)
            Dim canvas = New Bitmap(bm.Width * 2, bm.Height * 2)
            Using g = Graphics.FromImage(canvas)
                g.Clear(Color.White)
                Dim cx = (canvas.Width - bm.Width) / 2
                Dim cy = (canvas.Height - bm.Height) / 2
                g.DrawImage(bm, New Point(cx, cy))
    
                Dim upBound = Rectangle.FromLTRB(0, 0, canvas.Width, cy - 1)
                DrawTextBox(g, upBound, txtNombreProducto)
    
                Dim lowBound = Rectangle.FromLTRB(0, cy + bm.Height + 1,
                                                  canvas.Width, canvas.Height)
                DrawTextBox(g, lowBound, txtCodigoProducto)
    
            End Using
            PictureBox1.Image = canvas
        End Using
    
    End Sub
    
    Sub DrawTextBox(g As Graphics, bounds As Rectangle, box As TextBox)
        TextRenderer.DrawText(g, box.Text, box.Font, bounds, box.ForeColor)
    End Sub
    

    enter image description here

    ずいぶん小さいけど、ちゃんとバーコードリーダーで読めるのかな?

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. KOZ6.0 6,300 Reputation points
    2023-10-01T23:30:40.31+00:00

    please delete.

    0 comments No comments

  2. ELIRDFUL 185 Reputation points
    2023-10-02T22:51:50.2333333+00:00

    Resuelto 100x%

    Gracias