Spire.Barcode is a professional barcode library specially designed for .NET developers (C#, VB.NET, ASP.NET, .NET Core) and Java developers (J2SE and J2EE) to generate, read and scan 1D & 2D barcodes.

Tue Nov 24, 2015 5:29 am

Hi all,
I'm using VB.net. I use this code to generate a QR code and put it in a picturebox for later printing.

Code: Select all
Dim settings As New BarcodeSettings()
settings.Data = "123456"
settings.Type = BarCodeType.QRCode
Dim generator As New BarCodeGenerator(settings)
Me.pictureBox1.Image = generator.GenerateImage()


My questions are:

1. Can I specify the size/resolution of the QR code image generated, e.g. 500x500pixels ?
2. If, let say the QR code image is 500x500pixels but I want the code area is 400x400pixels in the middle, e.g. 50pixels margins for all directions. Can I do that? and how?

Thanks a lot.

ducphu
 
Posts: 11
Joined: Tue Nov 24, 2015 5:13 am

Tue Nov 24, 2015 7:04 am

Hi,

Please try the following code.
Code: Select all
Dim setting As New BarcodeSettings()

setting.Data = "123456"
setting.Type = BarCodeType.QRCode
setting.LeftMargin = 50 * 0.26F
setting.RightMargin = 50 * 0.26F
setting.TopMargin = 50 * 0.26F
setting.BottomMargin = 50 * 0.26F
setting.X = 400 * 0.013F
setting.Y = 400 * 0.013F
setting.ShowText = False

Dim generator As New BarCodeGenerator(setting)
Dim barcode As Image = generator.GenerateImage()
barcode.Save("..\..\barcode.png")


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Nov 24, 2015 11:23 am

Hi,
Thanks for the answer.

1. Can you explain about the 0.26F, and 0.013F ? What do these two values mean? Are they fixed if the barcode size is different? If not then how to calculate them
2. Also, it seems that we do not have any option to change the text (bottom text) of a barcode?? I only can find setting.ShowText and settings.TopText but not settings.Text ??
3. With a top margin of 50pixels and settings.ShowTopText = True, the toptext is placed at the border of the barcode image, i.e. far a part from the QR code. Can I place it near to the QR code instead?
4. Can I change the text size?

ducphu
 
Posts: 11
Joined: Tue Nov 24, 2015 5:13 am

Wed Nov 25, 2015 7:01 am

Hi,

1. The unit of the margin attributes(LeftMargin, Right, BottomMargin, TopMargin) and the unit of the bar code attributes( X, Y) both are not pixe, for example, the margin attributes is millimeter. 0.26F and 0.013F are conversion ratio with pixel, which are fixed.
2. Please use setting.Data =newText to change the text of a barcode.
3. Please use setting.TextMargin =spaceV to adjust the space between barcode and text.
4. Please use setting.TextFont = new Font(setting.TextFont.Name, newSize); to change the text size.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Nov 25, 2015 2:38 pm

I tried:

Code: Select all
settings = New BarcodeSettings()
            settings.Data = "Testing"
            settings.Type = BarCodeType.QRCode
            settings.ShowText = True


But the text shown is "12345"??

And setting.TextMargin, setting.TextFont only aplly to text but not TopText. Can I do the same thing with TopText?

ducphu
 
Posts: 11
Joined: Tue Nov 24, 2015 5:13 am

Thu Nov 26, 2015 3:40 am

Hi,

Please use the code setting.Data2D ="Testing".
Please kindly notice that setting.TextMargin and setting.TextFont only work for setting.Data2D or setting.Data.
If you want to display the data on top, please use setting.ShowTopText=true.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.BarCode