Type zint_render_line
x as single
y as single
length as single
width as single
pNext as DWord
end type
Type zint_render_string
x as single
y as single
fsize as single
width as single
length as Long
pText as Byte
pNext as DWord
end type
Type zint_render_ring
x as single
y as single
radius as single
line_width as single
pNext as DWord
end type
Type zint_render_hexagon
x as single
y as single
height as single
pNext as DWord
end type
Type zint_render
width as DWord
height as DWord
pLines as DWord 'struct zint_render_line *lines; /* Pointer to first line */
pStrings as dword 'struct zint_render_string *strings; /* Pointer to first string */
pRings as DWord 'struct zint_render_ring *rings; /* Pointer to first ring */
phexagons as DWord 'struct zint_render_hexagon *hexagons; /* Pointer to first hexagon */
end type
' struct zint_symbol {
' int symbology;
' int height;
' int whitespace_width;
' int border_width;
' int output_options;
' char fgcolour[10];
' char bgcolour[10];
' char outfile[256];
' float scale;
' int option_1;
' int option_2;
' int option_3;
' int show_hrt;
' int input_mode;
' int eci;
' unsigned char text[128];
' int rows;
' int width;
' char primary[128];
' unsigned char encoded_data[200][143];
' int row_height[200]; /* Largest symbol is 189 x 189 Han Xin */
' char errtxt[100];
' char *bitmap;
' int bitmap_width;
' int bitmap_height;
' unsigned int bitmap_byte_length;
' float dot_size;
' struct zint_render *rendered;
' int debug;
' };
'
Type zint_symbol
symbology as Long
height as Long
whitespace_width as Long
border_width as Long
output_options as long
fgcolour(10) as Byte
bgcolour(10) as byte
outfile as string * 256
scale as single
option_1 as Long
option_2 as Long
option_3 as Long
show_hrt as Long
input_mode as Long
eci as Long
stext as string * 128
rows as Long
width as Long
primary as string * 128
encoded_data(200,143) as Byte
row_height(200) as Long
errtxt as string * 100
pbitmap as dword
bitmap_width as Long
bitmap_height as Long
bitmap_byte_length as Long
dot_size as single
pRendered as dword 'struct zint_render *rendered;
debug as Long
end type
'ZINT_EXTERN struct zint_symbol *ZBarcode_Create(void);
DECLARE FUNCTION ZBarcode_Create LIB "zint.dll" ALIAS "ZBarcode_Create" () AS DWord
'ZINT_EXTERN void ZBarcode_Clear(struct zint_symbol *symbol);
DECLARE sub ZBarcode_Clear LIB "zint.dll" ALIAS "ZBarcode_Clear" (byval lSymbol as DWord)
'ZINT_EXTERN void ZBarcode_Delete(struct zint_symbol *symbol);
DECLARE sub ZBarcode_Delete LIB "zint.dll" ALIAS "ZBarcode_Delete" (byval lSymbol as DWord)
'
'ZINT_EXTERN int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int in_length);
DECLARE FUNCTION ZBarcode_Encode LIB "zint.dll" ALIAS "ZBarcode_Encode" (byval lSymbol as DWord, byval zSource as asciiz ptr, byval in_length as Long) AS long
'ZINT_EXTERN int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename);
'ZINT_EXTERN int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle);
DECLARE FUNCTION ZBarcode_Print LIB "zint.dll" ALIAS "ZBarcode_Print" (byval lSymbol as DWord, byval rotate_angle as Long) AS Long
'ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
'ZINT_EXTERN int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle);
'
'ZINT_EXTERN int ZBarcode_Render(struct zint_symbol *symbol, const float width, const float height);
'
'ZINT_EXTERN int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle);
DECLARE FUNCTION ZBarcode_Buffer LIB "zint.dll" ALIAS "ZBarcode_Buffer" (byval lSymbol as DWord, byval rotate_angle as Long) AS Long
'ZINT_EXTERN int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
'ZINT_EXTERN int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle);
'
'ZINT_EXTERN int ZBarcode_ValidID(int symbol_id);
DECLARE FUNCTION ZBarcode_ValidID LIB "zint.dll" ALIAS "ZBarcode_ValidID" (ByVal SymbolID as Long) AS Long
'ZINT_EXTERN int ZBarcode_Version();
DECLARE FUNCTION ZBarcode_Version LIB "zint.dll" ALIAS "ZBarcode_Version" () AS long
' http://zint.org.uk/Manual.aspx?type=p&page=5
Uses "UI"
uses "console"
' -- ID numbers of controls
Begin ControlID
%cCanvasDB
%bBarCode
%bClose
End ControlID
Type BGRA
B As Byte
G As Byte
R As Byte
A As Byte
End Type
' -- Create dialog here
FUNCTION TBMAIN()
LOCAL hDlg AS DWORD
Dialog NEW pixels, 0, "thinBasic and zint lib",-1,-1, 640, 300, _
%WS_POPUP Or %WS_VISIBLE Or _
%WS_CLIPCHILDREN Or %WS_CAPTION OR _
%WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg
' -- Place controls here
dim cx, cy as long
'dialog pixels hDlg, 400, 400 to units cx, cy
Control ADD CANVAS, hDlg, %cCanvasDB, "", 0, 0, 640, 200
Control ADD BUTTON, hDlg, %bBarCode , "Redraw" , 10, 250, 50, 25, Call bModifyBitmapProc
Control ADD BUTTON, hDlg, %bClose , "Close" , 100, 250, 50, 25, Call bCloseProc
DIALOG SHOW MODAL hDlg, CALL dlgProc
END FUNCTION
' -- Callback for dialog
CALLBACK FUNCTION dlgProc()
' -- Test for messages
SELECT CASE CBMSG
Case %WM_INITDIALOG
DrawBarCode(CBHNDL)
CASE %WM_CLOSE
' -- Put code to be executed before dialog end here
END SELECT
END FUNCTION
' -- Callback for close button
CallBack Function bCloseProc()
If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
DIALOG END CBHNDL
END IF
END IF
End Function
CallBack Function bModifyBitmapProc()
If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
DrawBarCode(CBHNDL)
Dialog SET TEXT CBHNDL, "OK " & Timer
End If
End If
End Function
function DrawBarCode(byval hWnd as Long) as Long
dim pSymbol as zint_symbol ptr
DWord lSymbol
string sText = "thinBASIC & zint rocks!" & $NUL
printl "Version:", ZBarcode_Version
lSymbol = ZBarcode_Create
PrintL "Symbol:", lSymbol
pSymbol = lSymbol
pSymbol.symbology = 20 'Code 128
'pSymbol.symbology = 58 'QR Code
'pSymbol.symbology = 71 'Data MATRIX
pSymbol.outfile = "xxx.bmp"
pSymbol.input_mode = 0 'DATA_MODE
'pSymbol.scale = 0.8
'printl "BARCODE_CODE128 :", ZBarcode_ValidID(20)
printl "Current pSymbol.symbology", pSymbol.symbology
printl "ZBarcode_Encode :", ZBarcode_Encode(lSymbol, sText, 0)
printl "ZBarcode_Buffer :", ZBarcode_Buffer(lSymbol, 0)
'printl "ZBarcode_Print :", ZBarcode_Print(lSymbol, 0)
printl "pSymbol.bitmap_width", pSymbol.bitmap_width
printl "pSymbol.bitmap_height", pSymbol.bitmap_height
CANVAS_Attach(hWnd, %cCanvasDB, %TRUE)
canvas_clear(rgb(255, 255, 255))
CANVAS_Redraw
long y, x, i
Long red, blue, green
dim nPixels = (pSymbol.bitmap_width) * (pSymbol.bitmap_height) * 4
dim lColors(nPixels) as byte at pSymbol.pbitmap
i = 1
for y = 1 to pSymbol.bitmap_height
for x = 1 to pSymbol.bitmap_width
red = lColors(i)
green = lColors(i + 1)
blue = lColors(i + 2)
Canvas_SetPixel(x, y, rgb(red, green, blue) )
i += 3
Next
Next
ZBarcode_Delete(lSymbol)
CANVAS_Redraw
end Function
Bookmarks