how to generat square barcode image

phwater
Posts: 1
Joined: Thu Jul 20, 2017 5:24 pm

how to generat square barcode image

Postby phwater » Thu Jul 20, 2017 5:33 pm

i want to get the barcode image by barcode ID with type AR_Matrix_Code_4x4, but i can not open the link : http://www.artoolworks.com/support/applications/marker/

can any one tell me how to do this, thx.

sturner
Posts: 11
Joined: Thu Sep 29, 2016 3:54 am

Re: how to generat square barcode image

Postby sturner » Thu Jul 20, 2017 11:05 pm

Here is a VBA macro I used to generate my images. Paste it into a module in Excel.

Option Explicit
Option Compare Text

Private Type typHEADER
strType As String * 2 ' Signature of file = "BM"
lngSize As Long ' File size
intRes1 As Integer ' reserved = 0
intRes2 As Integer ' reserved = 0
lngOffset As Long ' offset to the bitmap data (bits)
End Type

Private Type typINFOHEADER
lngSize As Long ' Size
lngWidth As Long ' Height
lngHeight As Long ' Length
intPlanes As Integer ' Number of image planes in file
intBits As Integer ' Number of bits per pixel
lngCompression As Long ' Compression type (set to zero)
lngImageSize As Long ' Image size (bytes, set to zero)
lngxResolution As Long ' Device resolution (set to zero)
lngyResolution As Long ' Device resolution (set to zero)
lngColorCount As Long ' Number of colors (set to zero for 24 bits)
lngImportantColors As Long ' "Important" colors (set to zero)
End Type

Private Type typPIXEL
bytB As Byte ' Blue
bytG As Byte ' Green
bytR As Byte ' Red
End Type

Private Type typBITMAPFILE
bmfh As typHEADER
bmfi As typINFOHEADER
bmbits() As Byte
End Type

Private PI As Double
Private myTol As Double

Sub Main()
Dim i As Integer

PI = Atn(1) * 4
myTol = 0.0001

For i = 1 To 1024
CreateSquareBitmap i
DoEvents
Next
End Sub

Public Function LongToRGB(theColor As Long, iRed As Integer, iGreen As Integer, iBlue As Integer) As Boolean
'
Dim lColor As Long
lColor = theColor 'work long
iRed = lColor Mod 256 'get red component
iGreen = (lColor \ 256) Mod 256 'get green component
iBlue = (lColor \ 256 \ 256) Mod 256 'get blue component
'
LongToRGB = True
End Function

Public Function RGBToLong(iRed As Integer, iGreen As Integer, iBlue As Integer) As Long
Dim lColor As Long

lColor = iBlue
lColor = lColor * 256
lColor = lColor + iGreen
lColor = lColor * 256
lColor = lColor + iRed

RGBToLong = lColor
End Function

Sub DrawRectangle(x As Integer, y As Integer, w As Integer, h As Integer, ByRef myArray As Variant)
Dim i As Integer
Dim j As Integer

For i = 0 To h - 1
For j = 0 To w - 1
myArray(x + j, y + i) = 0
Next
Next
End Sub

Sub SetPixel(x As Integer, y As Integer, ByRef myArray As Variant)
DrawRectangle x * 64, y * 64, 64, 64, myArray
End Sub

Sub SetPixel2(x As Integer, y As Integer, ByRef myArray As Variant)
DrawRectangle 128 + x * 64, 128 + (3 - y) * 64, 64, 64, myArray
End Sub

Sub CreateSquareBitmap(ByVal nVal As Integer)
Dim i As Integer, j As Integer, k As Long, l As Long, n As Integer
'
Dim bmpFile As typBITMAPFILE
Dim lngRowSize As Long
Dim lngPixelArraySize As Long
Dim lngFileSize As Long
'
Dim bytRed As Integer, bytGreen As Integer, bytBlue As Integer
Dim lngRGBColor() As Long
'
Dim strBMP As String
Dim d As Double
Dim nVal2 As Integer
Dim iBit As Integer


'
' Create the BMP data structures based on the selected cells.
'
With bmpFile
' BMP Header
With .bmfh
.strType = "BM" ' Basic BMP file
.lngSize = 0 ' Determine later (total file size in bytes)
.intRes1 = 0 ' Set to zero
.intRes2 = 0 ' Set to zero
.lngOffset = 54 ' Location where the bitmap data start
End With
' DIB Header
With .bmfi
.lngSize = 40 ' This will be a Version 3 BMP
.lngWidth = 512 ' Number of pixels wide
.lngHeight = 512 ' Number of pixels high
.intPlanes = 1 ' Set to one
.intBits = 24 ' 24 bits per pixel (RGB)
.lngCompression = 0 ' No compression
.lngImageSize = 0 ' Can be set to zero
.lngxResolution = 0 ' Set to zero
.lngyResolution = 0 ' Set to zero
.lngColorCount = 0 ' Set to zero (no color pallette)
.lngImportantColors = 0 ' Set to zero
End With
' Bitmap pixel array (ensure 32 bit boundary alignment!)
lngRowSize = Round(.bmfi.intBits * .bmfi.lngWidth / 32) * 4
lngPixelArraySize = lngRowSize * .bmfi.lngHeight
'
ReDim .bmbits(lngPixelArraySize) ' Total number of bytes to store padded pixel array
'
' Read color data from cells (no color is considered white)
' Start from bottom row and work up. Pad each row to an even
' 4 byte boundary if required.
' NOTE: Instead of reading colors, you can read numbers and get the "bytBlue", "bytGreen",
' and "bytRed" values directly from those numbers.
'
ReDim lngRGBColor(511, 511)
For i = 0 To 511
For j = 0 To 511
lngRGBColor(i, j) = RGBToLong(255, 255, 255)
Next
Next

For i = 0 To 7
SetPixel i, 0, lngRGBColor
SetPixel i, 1, lngRGBColor
SetPixel i, 6, lngRGBColor
SetPixel i, 7, lngRGBColor
Next
For i = 2 To 5
SetPixel 0, i, lngRGBColor
SetPixel 1, i, lngRGBColor
SetPixel 6, i, lngRGBColor
SetPixel 7, i, lngRGBColor
Next
SetPixel2 0, 0, lngRGBColor
SetPixel2 0, 3, lngRGBColor

i = 3
j = 2
nVal2 = nVal
While nVal2 > 0
If nVal2 Mod 2 = 1 Then
SetPixel2 j, i, lngRGBColor
nVal2 = nVal2 - 1
End If
nVal2 = nVal2 / 2

resetPos2:
j = j - 1

resetPos:
If j < 0 Then
i = i - 1
j = 3
GoTo resetPos
End If
If i = 3 And j = 0 Then GoTo resetPos2
If i = 0 And j = 0 Then GoTo resetPos2
Wend

k = -1
For j = 0 To 511
For i = 0 To 511
If (LongToRGB(lngRGBColor(i, j), bytRed, bytGreen, bytBlue)) Then
k = k + 1
.bmbits(k) = bytBlue
k = k + 1
.bmbits(k) = bytGreen
k = k + 1
.bmbits(k) = bytRed
Else
k = k + 1
.bmbits(k) = 255
k = k + 1
.bmbits(k) = 255
k = k + 1
.bmbits(k) = 255
End If
Next i ' For each column...
If (512 * .bmfi.intBits / 8 < lngRowSize) Then ' Add padding if required
For l = 512 * .bmfi.intBits / 8 + 1 To lngRowSize
k = k + 1
.bmbits(k) = 0
Next l
End If
Next j ' For each row, starting at the bottom and working up...

'
' The structures have all been loaded. Calculate file size
' and then dump the data to a file.
'
.bmfh.lngSize = 14 + 40 + lngPixelArraySize
'
End With ' Defining bmpFile
'
strBMP = "C:\Path To Your Folder" & "\Image" & Format(nVal, "000") & ".BMP"
'
Open strBMP For Binary Access Write As 1 Len = 1
'
Put 1, 1, bmpFile.bmfh
Put 1, , bmpFile.bmfi
Put 1, , bmpFile.bmbits
'
Close
'
End Sub

alexisdle
Posts: 10
Joined: Sat Jul 22, 2017 7:22 pm

Re: how to generat square barcode image

Postby alexisdle » Thu Aug 17, 2017 7:52 pm

Hi @sturner,


How can i change the marker size, because i need to generate the marker from the AR_MATRIX_CODE_4x4?

thank you in advance!!

sturner
Posts: 11
Joined: Thu Sep 29, 2016 3:54 am

Re: how to generat square barcode image

Postby sturner » Mon Sep 04, 2017 12:49 am

Hi alexisdle

This code is already for AR_MATRIX_CODE_4x4

ginaschwaer
Posts: 1
Joined: Mon Sep 18, 2017 5:15 am

Re: how to generat square barcode image

Postby ginaschwaer » Mon Sep 18, 2017 5:16 am

Noocube is for people who want to keep up on the latest breakthroughs in brain health and optimization and the related areas of neuroscience.


Return to “ARToolKit for Desktop v5.x”

Who is online

Users browsing this forum: No registered users and 1 guest