0

I am trying to generate a barcode with its text embedded under the very barcode itself but I can only generate the barcode without the text embedded on it.

Here is my code :

Public Function process_printbarcode(lbl169 As Label)

    Dim length As Integer = 1

    Dim mybarcode As Image = Code128Rendering.MakeBarcodeImage(lbl169.Text.ToString, Integer.Parse(length.ToString()), False)

    Admin_Menu.PictureBox3.Image = mybarcode

    Return True

End Function
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
Lucifer Rodstark
  • 206
  • 4
  • 14
  • You are missing some very fundamental aspects of datatypes. `.Text` properties are string, so there is no need to use `ToString()` on them; then if `length` is an integer then there is no need to convert it to string and then parse it back to an integer. There is no even a need for a variable as `1` ought to work – Ňɏssa Pøngjǣrdenlarp Nov 27 '17 at 19:15
  • 1
    After a quick glance at that project's source code, it doesn't look like the developer has included that option. You can either add the human-readable text to the Image yourself, or use a library that has that function built in such as [barcodelib](https://www.nuget.org/packages/BarcodeLib/)...see its `IncludeLabel` property – soohoonigan Nov 27 '17 at 19:19
  • 1
    You should also know that deleting your old posts is usually a pretty bad idea. If they are Downvoted the DVs still count against you but its bad because there is no chance anyone can upvotes any changes/fixes you apply. It there are answers on them, it is very very bad and counts even more against you – Ňɏssa Pøngjǣrdenlarp Nov 27 '17 at 19:21
  • ...not to mention it is of course it is a severe disincentive to answering anything from you when the chances are darn good you'll just delete their work – Ňɏssa Pøngjǣrdenlarp Nov 27 '17 at 19:26
  • @Plutonix uhmm, tbh I didn't delete them. They deleted my account because of me answering my sister's questions – Lucifer Rodstark Nov 27 '17 at 19:35
  • @Plutonix is it fine to delete a question with no answer? Cause the other guy told me that my library has no IncludeLabel property so I won’t need this question anymore or rather I cannot mark his comment as an answer – Lucifer Rodstark Nov 28 '17 at 09:44
  • @soohoonigan add the ‘human readable’ text? You meant just add a paragraph that contains the text right? – Lucifer Rodstark Nov 28 '17 at 09:46
  • Yes, it adds a text line below or above the barcode that shows the encoded value – soohoonigan Nov 28 '17 at 14:10
  • @Plutonix can you help me with a little looping on my other question? – Lucifer Rodstark Nov 29 '17 at 17:17

1 Answers1

0

GenCode128 does not include an option to display the encoded value below the barcode as part of the image. You could use the Bitmap and Graphics classes to modify the image and add text to it, but I think it would be easier to just use a different DLL that comes with that functionality. One I've personally used is BarcodeLib. You can add it to your project in a few ways:

  1. Add it as a Nuget Package by running Install-Package BarcodeLib -Version 1.0.0.23 in your package manager console
  2. Download the project's GitHub source-code and build the BarcodeLib.dll yourself

Either way, just add it as a reference in your solution. BarcodeLib has got a lot more barcode parameters available for you to set (and several other encoding types as well), and it's very easy to create them:

Private Function Code128Image(ByVal value As String, _
                      Optional height As Integer = 100, _
                      Optional barWidth As Integer = 1, _
                      Optional labelIncluded As Boolean = True, _
                      Optional labelPosition As BarcodeLib.LabelPositions = LabelPositions.BOTTOMCENTER, _
                      Optional barcodeRotation As System.Drawing.RotateFlipType = System.Drawing.RotateFlipType.RotateNoneFlipNone) _
                  As System.Drawing.Image
    Using barcodeImage As New BarcodeLib.Barcode
        With barcodeImage
            .Height = height
            .BarWidth = barWidth
            .IncludeLabel = labelIncluded
            .LabelPosition = labelPosition
            .RotateFlipType = barcodeRotation
            Return .Encode(BarcodeLib.TYPE.CODE128, value)
        End With
    End Using
End Function

Calling Admin_Menu.PictureBox3.Image = Code128Image("123456789") would get you:

code128img.png

soohoonigan
  • 2,342
  • 2
  • 10
  • 18
  • Nice answer bro, but I decided to just add a human readable text which is your answer too and I had a bit of a problem now with some loops would you like me to link you the question so you can help me? Only if you’d like to – Lucifer Rodstark Nov 29 '17 at 15:36