jordao76 / nbarcodes

.NET library to generate common 1D barcodes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to save the generated barcode image to a specific location

GoogleCodeExporter opened this issue · comments

Hi, I have implemented the code and the dll file into my code and while 
debugging however it is not showing any error, but to check the barcode i am 
not aware where it is saved OR how to save it to a specific location and into 
the specific image format.......... so please help me out

The Code i have written is as such:
Imports NBarCodes
Public Class form1
 Private Sub nbarcode()
 Dim barcode As NBarCodes.Forms.BarCodeControl = New NBarCodes.Forms.BarCodeControl

        barcode.Type = NBarCodes.BarCodeType.Code128
        barcode.Data = Label1.Text

        BarCodeControl1.Visible = True

        Dim generator = New BarCodeGenerator(barcode)

        Using barcodeimage = generator.generateimage()
        End Using
 End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
               Call nbarcode()
    End Sub

End Class


Original issue reported on code.google.com by myselfav...@gmail.com on 30 Nov 2011 at 8:10

Hello,

When you call BarCodeGenerator::GenerateImage, you get back a 
[System.Drawing.Image](http://msdn.microsoft.com/en-us/library/system.drawing.im
age.aspx) instance. Your image is in-memory. To save it to disk, you can use 
the [Save 
method](http://msdn.microsoft.com/en-us/library/system.drawing.image.save.aspx):

Using barcodeimage = generator.generateimage()
  barcodeimage.Save("my_barcode.png", ImageFormat.Png)
End Using

Hope this helps.

Original comment by rodrigo....@gmail.com on 2 Dec 2011 at 12:47

  • Changed state: Done
  • Added labels: Type-Task
  • Removed labels: Type-Defect
I also noticed that you're using the NBarCodes.Forms.BarCodeControl just to 
generate an image and save it to disk. If you don't want to show the barcode in 
a Form, you might as well just use the API to generate the barcode 
programmatically. Use the NBarCodes.BarCodeSettings class as described here: 
http://code.google.com/p/nbarcodes/#API

Original comment by rodrigo....@gmail.com on 2 Dec 2011 at 12:53

If, on the other hand, you do want to show the control on a Form, it seems you 
already have an instance to use (BarCodeControl1). Your code could simply be:

    BarCodeControl1.Visible = True 
    BarCodeControl1.Type = NBarCodes.BarCodeType.Code128
    BarCodeControl1.Data = Label1.Text

Original comment by rodrigo....@gmail.com on 2 Dec 2011 at 12:56