BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

Post your working scripts, libraries and tools
newbieforever
Posts: 400
Joined: 24 Aug 2016, 03:34

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

29 Nov 2018, 15:44

PS:
I use now Zint to generate my codes.
But...to resume my original question:
Is there really no approach or attempt of a solution in AHK to generate datamatrix codes?
User avatar
Gio
Posts: 700
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

30 Nov 2018, 08:53

Is there really no approach or attempt of a solution in AHK to generate datamatrix codes?
I have taken a look into the DataMatrix standards before and they seem to be very similar to QR Codes in many technical aspects (use of reed solomon error correction, use of finder patterns, disposing the bits in specific ways, etc). If my experience in developing the QR Code generator function is to be accounted for, i would say it would take around a month to develop a complete DataMatrix generator fully coded in AutoHotkey from scratch. A simpler version, such as fixed length, fixed ECL, ASCII only, etc, should probably be doable in a few days though. Having the QR Code generator as a guide should decrease the development time a little too.

As mentioned, i currently have no plans of doing this as i am particularly focused into some other projects. But what size are the data strings that you are trying to encode? It is ASCII data? Does a fixed version suffices or do you absolutely need the smallest possible matrix? Does it have to be GS1 compatible? If you are willing to develop it yourself, i may be able to help with the most confusing parts (i.e.: implementing the Reed-Solomon error correction, etc) provided that you are willing to share the code with the community afterwards, of course.
wodzu
Posts: 3
Joined: 06 Dec 2018, 02:21

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

06 Dec 2018, 02:32

First of all, I would like to thank you @Gio for this awesome script you made - brilliant job!

I am using this part of your code that generates a 128 barcode. It works very good for my purpose but I need to make it bigger somehow. I'm printing this barcode on a Zebra printer and the quality is not good enough. I tryed to change the bitmap resolution but this don't seem to work. Could you help me here, please?

Here's the part of the code I'm using:

Code: Select all

MATRIX_TO_PRINT := BARCODER_GENERATE_CODE_128B(KodOdbioru)
if (MATRIX_TO_PRINT = 1)
{
Msgbox, 0x10, Error, The input message is either blank or contains characters that cannot be encoded in CODE_128B.

}
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system

}
HEIGHT_OF_IMAGE := 20 ; 20 is the arbitrary height of the Barcode image for this example. You can chage it to any number to increase/decrease the height of the image. Since a scanner must get an accurate vision of a full line, a taller image may offer a higher chance that a physically damaged print will have at least 1 fully readable line (This should not be confused with QR Codes Error Correction Level protection though).
pBitmap := Gdip_CreateBitmap(MATRIX_TO_PRINT.MaxIndex() + 8, HEIGHT_OF_IMAGE + 25) ; Adding 8 pixels to the width here as a "quiet zone" for the image. This serves to improve the printed code readability.
Gdip_BitmapSetResolution(pBitmap,600,600)
G := Gdip_GraphicsFromImage(pBitmap)
Gdip_SetSmoothingMode(pBitmap, 3)
pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
Gdip_FillRectangle(G, pBrush, 0, 0, MATRIX_TO_PRINT.MaxIndex() + 8, HEIGHT_OF_IMAGE + 25) ; Same as above
Gdip_DeleteBrush(pBrush)
Loop % HEIGHT_OF_IMAGE
{
CURRENT_ROW := A_Index
Loop % MATRIX_TO_PRINT.MaxIndex()
{
CURRENT_COLUMN := A_Index
If (MATRIX_TO_PRINT[A_Index] = 1)
{
Gdip_SetPixel(pBitmap, CURRENT_COLUMN + 1, CURRENT_ROW, 0xFF000000) ; Adding 3 to the current column and the current row to skip the quiet zones.
}
}
}

CURRENT_ROW := "", CURRENT_COLUMN := ""
Options = x30 y22 cFF000000 r1 s20
Gdip_TextToGraphics(G, KodOdbioru, Options, "Arial")

StringReplace, FILE_NAME_TO_USE, KodOdbioru, `" ; We can't use all the characters that byte mode can encode in the name of the file. So we are replacing them here (if they exist).
FILE_PATH_AND_NAME := A_ScriptDir . "\input\" . SubStr(RegExReplace(FILE_NAME_TO_USE, "[\t\r\n\\\/\`:\`?\`*\`|\`>\`<]"), 1, 20) . ".png" ; Same as above. We will only use the first 20 characters for the file name in this example.
Gdip_SaveBitmapToFile(pBitmap, FILE_PATH_AND_NAME)
Gdip_DisposeImage(pBitmap)
User avatar
Gio
Posts: 700
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

06 Dec 2018, 09:05

Hello Wodzu.

Glad you found the library useful :thumbup:

The example below allows you to adjust pixel-width based on the desired numbers for the thinnest lines. Also, you can adjust image height in pixels (i suggest using 20x the base pixel-width you chose for the pixel height of the image).

Code: Select all

inputbox, PixelSize,, Type in the desired PIXEL-WIDTH for the thinnest bars.
inputbox, HEIGHT_OF_IMAGE,, Type in the desired PIXEL-HEIGHT of the image.
inputbox, MESSAGE_TO_ENCODE,, Type in the MESSAGE you wish to encode.

MATRIX_TO_PRINT := BARCODER_GENERATE_CODE_128B(MESSAGE_TO_ENCODE)
if (MATRIX_TO_PRINT = 1)
{
Msgbox, 0x10, Error, The input message is either blank or contains characters that cannot be encoded in CODE_128B.

}
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system

}
pBitmap := Gdip_CreateBitmap(((MATRIX_TO_PRINT.MaxIndex() + 8) * PixelSize) , HEIGHT_OF_IMAGE + 25) ; Adding 8 pixels to the width here as a "quiet zone" for the image. This serves to improve the printed code readability.
Gdip_BitmapSetResolution(pBitmap,600,600)
G := Gdip_GraphicsFromImage(pBitmap)
Gdip_SetSmoothingMode(pBitmap, 3)
pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
Gdip_FillRectangle(G, pBrush, 0, 0, ((MATRIX_TO_PRINT.MaxIndex() + 8) * PixelSize), HEIGHT_OF_IMAGE + 25) ; Same as above
Gdip_DeleteBrush(pBrush)
Loop % HEIGHT_OF_IMAGE
{
CURRENT_ROW := A_Index
Loop % MATRIX_TO_PRINT.MaxIndex()
{
CURRENT_COLUMN := A_Index
If (MATRIX_TO_PRINT[A_Index] = 1)
{
	Loop % PixelSize
	{
		; Gdip_SetPixel(pBitmap, CURRENT_COLUMN + 1, CURRENT_ROW, 0xFF000000) ; Adding 3 to the current column and the current row to skip the quiet zones.
		Gdip_SetPixel(pBitmap, (CURRENT_COLUMN * PixelSize) + (3*PixelSize) - 1 + A_Index, CURRENT_ROW, 0xFF000000) ; Adding 3 to the current column and the current row to skip the quiet zones.
	}
}
}
}

CURRENT_ROW := "", CURRENT_COLUMN := ""
Options = x30 y22 cFF000000 r1 s20
Gdip_TextToGraphics(G, KodOdbioru, Options, "Arial")

StringReplace, FILE_NAME_TO_USE, KodOdbioru, `" ; We can't use all the characters that byte mode can encode in the name of the file. So we are replacing them here (if they exist).
FILE_PATH_AND_NAME := A_ScriptDir . "\input\" . SubStr(RegExReplace(FILE_NAME_TO_USE, "[\t\r\n\\\/\`:\`?\`*\`|\`>\`<]"), 1, 20) . ".png" ; Same as above. We will only use the first 20 characters for the file name in this example.
Gdip_SaveBitmapToFile(pBitmap, FILE_PATH_AND_NAME)
Gdip_DisposeImage(pBitmap)

This post by JoeWinograd contains an example in case you also need to adjust the dimensions for a QR Code image.
mattkingston
Posts: 17
Joined: 14 Oct 2016, 13:17

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

25 Jun 2019, 07:56

Excellent work!
Can I ask though, is it possible to increase the resolution of the generated barcode.
Id like to scale it a to a larger size without blurring the code lines.

Thanks in advance.
User avatar
Gio
Posts: 700
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

25 Jun 2019, 11:54

Yes, there are actually a few examples on how to do it in the replies to the topic already. Which type of barcode you are using?
baboo1308
Posts: 2
Joined: 20 Sep 2019, 06:49

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

20 Sep 2019, 06:58

We issue bar codes.
CODE39 Line 4 and QR Code Line 1 are used.
The comma[,] is not implemented during the QR code progress, but is expressed as zero.
Is there any way to generate a comma[,] when issuing QR codes?
User avatar
Gio
Posts: 700
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

20 Sep 2019, 09:07

Hello Baboo1308.

I tried the example 2 in the first post of this topic and was actually able to generate messages that included commas no problem.

:arrow: Besides kanji, there are 3 code modes in QR Codes:
Numeric mode allows numbers only
Alphanumeric mode allows Numbers, UPPERCASE letters A-Z and symbols ; $, %, *, +, -, ., /, :, and \.
Byte mode allows the full ASCII table.

You should use the later if you wish to write commas. If you are using the Barcoder library, it will choose the best mode based on your input message, but even if this auto-choice is not working, you can also force the function BARCODER_GENERATE_QR_CODE() to use Byte mode only by assigning value 3 as the second parameter of the function.
baboo1308
Posts: 2
Joined: 20 Sep 2019, 06:49

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

20 Sep 2019, 09:22

Hello, GIO

I did TEST now.

Barcode scanning works so well.
Thank you so much.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: leo007, thebbandit and 45 guests