【已解决】可不可以让AU3生成的条形码保存为图片?
本帖最后由 Netfox 于 2011-3-4 22:05 编辑如图 贴上生成部份的代码看看 顶起,谁有条码生成的算法呀!》 ;Code 128 Barcode Generator - Andy M 2008
#include <array.au3>
#include <file.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
Opt("GUIOnEventMode", 1)
;*************************************************************************************
; Declare Vars
;*************************************************************************************
Global $array
Global $CodeArray
Global $data
Global $L
;*************************************************************************************
; Assign Code 128 Pattern array
;*************************************************************************************
; Items are "???"
$array = "0? ?00?11011001100"
$array = "1?!?01?11001101100"
$array = '2?"?02?11001100110'
$array = "3?#?03?10010011000"
$array = "4?$?04?10010001100"
$array = "5?%?05?10001001100"
$array = "6?&?06?10011001000"
$array = "7?'?07?10011000100"
$array = "8?(?08?10001100100"
$array = "9?)?09?11001001000"
$array = "10?*?10?11001000100"
$array = "11?+?11?11000100100"
$array = "12?,?12?10110011100"
$array = "13?-?13?10011011100"
$array = "14?.?14?10011001110"
$array = "15?/?15?10111001100"
$array = "16?0?16?10011101100"
$array = "17?1?17?10011100110"
$array = "18?2?18?11001110010"
$array = "19?3?19?11001011100"
$array = "20?4?20?11001001110"
$array = "21?5?21?11011100100"
$array = "22?6?22?11001110100"
$array = "23?7?23?11101101110"
$array = "24?8?24?11101001100"
$array = "25?9?25?11100101100"
$array = "26?:?26?11100100110"
$array = "27?;?27?11101100100"
$array = "28?<?28?11100110100"
$array = "29?=?29?11100110010"
$array = "30?>?30?11011011000"
$array = "31???31?11011000110"
$array = "32?@?32?11000110110"
$array = "33?A?33?10100011000"
$array = "34?B?34?10001011000"
$array = "35?C?35?10001000110"
$array = "36?D?36?10110001000"
$array = "37?E?37?10001101000"
$array = "38?F?38?10001100010"
$array = "39?G?39?11010001000"
$array = "40?H?40?11000101000"
$array = "41?I?41?11000100010"
$array = "42?J?42?10110111000"
$array = "43?K?43?10110001110"
$array = "44?L?44?10001101110"
$array = "45?M?45?10111011000"
$array = "46?N?46?10111000110"
$array = "47?O?47?10001110110"
$array = "48?P?48?11101110110"
$array = "49?Q?49?11010001110"
$array = "50?R?50?11000101110"
$array = "51?S?51?11011101000"
$array = "52?T?52?11011100010"
$array = "53?U?53?11011101110"
$array = "54?V?54?11101011000"
$array = "55?W?55?11101000110"
$array = "56?X?56?11100010110"
$array = "57?Y?57?11101101000"
$array = "58?Z?58?11101100010"
$array = "59?[?59?11100011010"
$array = "60?\?60?11101111010"
$array = "61?]?61?11001000010"
$array = "62?^?62?11110001010"
$array = "63?_?63?10100110000"
$array = "64?`?64?10100001100"
$array = "65?a?65?10010110000"
$array = "66?b?66?10010000110"
$array = "67?c?67?10000101100"
$array = "68?d?68?10000100110"
$array = "69?e?69?10110010000"
$array = "70?f?70?10110000100"
$array = "71?g?71?10011010000"
$array = "72?h?72?10011000010"
$array = "73?i?73?10000110100"
$array = "74?j?74?10000110010"
$array = "75?k?75?11000010010"
$array = "76?l?76?11001010000"
$array = "77?m?77?11110111010"
$array = "78?n?78?11000010100"
$array = "79?o?79?10001111010"
$array = "80?p?80?10100111100"
$array = "81?q?81?10010111100"
$array = "82?r?82?10010011110"
$array = "83?s?83?10111100100"
$array = "84?t?84?10011110100"
$array = "85?u?85?10011110010"
$array = "86?v?86?11110100100"
$array = "87?w?87?11110010100"
$array = "88?x?88?11110010010"
$array = "89?y?89?11011011110"
$array = "90?z?90?11011110110"
$array = "91?{?91?11110110110"
$array = "92?|?92?10101111000"
$array = "93?}?93?10100011110"
$array = "94?~?94?10001011110"
$array = "95?del?95?10111101000"
$array = "96?Fnc3?96?10111100010"
$array = "97?Fnc2?97?11110101000"
$array = "98?Shift?98?11110100010"
$array = "99?Code C?99?10111011110"
$array = "100?Fnc 4?Code B?10111101110"
$array = "101?Code A?Code A?11101011110"
$array = "102?Fnc 1?Fnc 1?11110101110"
;*************************************************************************************
; GUI
;*************************************************************************************
Global $hGui = GUICreate("Code 128 (B/C) Barcode Generator - AndyBiochem 2008", 613, 286)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
$Input = GUICtrlCreateInput("", 8, 8, 321, 25)
GUICtrlSetFont(-1,12)
GUICtrlCreateButton("Generate Barcode", 344, 8, 257, 25)
GUICtrlSetOnEvent(-1,"MakeBarcode")
Global $Label = GUICtrlCreateLabel("", 8, 48, 596, 225)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
;#####################################################################################
; LOOP
;#####################################################################################
While 1
Sleep(10)
WEnd
;#####################################################################################
; END LOOP
;#####################################################################################
Func MakeBarcode()
;*************************************************************************************
; Delete previous barcode
;*************************************************************************************
for $i = 1 to (UBound($L) - 1)
GUICtrlDelete($L[$i])
Next
;*************************************************************************************
; Generate Pattern
;*************************************************************************************
$Barcode = IdentifyCodeSwitches(GUICtrlRead($Input))
;*************************************************************************************
; Draw new Barcode
;*************************************************************************************
Dim $L
$i = 1
While $i <= StringLen($barcode)
$col = StringMid($barcode,$i,1)
if $col = 1 Then
$L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100)
GUICtrlSetBkColor(-1,0x000000)
Else
$L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100)
GUICtrlSetBkColor(-1,0xFFFFFF)
EndIf
$i += 1
WEnd
;==================================================================
;加入保存为图片
_ScreenCapture_CaptureWnd ("BarCode.jpg", $hGui);保存GUI为图片
;如果只要保存GUI的BarCode区域
;或_ScreenCapture_CaptureWnd ("BarCode.jpg", $hGui, [, $iLeft = 0[, $iTop = 0[, $iRight = -1[, $iBottom = -1]);见_ScreenCapture_CaptureWnd帮助
;==================================================================
EndFunc
Func IdentifyCodeSwitches($code)
;*************************************************************************************
; Identify where code switches should be
;*************************************************************************************
$i = 1
$CodeType = "B" ;always start with code type B
$len = StringLen($Code)
While $i <= $len
Select
Case $CodeType = "B"
if StringRegExp(StringMid($Code,$i,6),"(){3}") = 1 Then
$Code = StringMid($Code,1,$i - 1) & "?C?" & StringMid($Code,$i)
$CodeType = "C"
$i += 6 + 3
Else
$CodeType = "B"
$i += 1
EndIf
Case $CodeType = "C"
if StringRegExp(StringMid($Code,$i,2),"()") <> 1 Then
$Code = StringMid($Code,1,$i - 1) & "?B?" & StringMid($Code,$i)
$CodeType = "B"
$i += 2 + 3
Else
$CodeType = "C"
$i += 2
EndIf
EndSelect
$len = StringLen($Code)
WEnd
;*************************************************************************************
; Add start code B, if not already started C
;*************************************************************************************
if StringMid($Code,1,3) <> "?C?" then $Code = "?B?" & $Code
;*************************************************************************************
; Split to array, re-assemble code switches
;*************************************************************************************
$CodeArray = StringSplit($code,"")
for $i = 1 to (UBound($CodeArray) - 3)
Select
case $CodeArray[$i] & $CodeArray[$i+1] & $CodeArray[$i+2] = "?B?"
$CodeArray[$i] = ""
$CodeArray[$i+1] = ""
$CodeArray[$i+2] = ""
case $CodeArray[$i] & $CodeArray[$i+1] & $CodeArray[$i+2] = "?C?"
$CodeArray[$i] = ""
$CodeArray[$i+1] = ""
$CodeArray[$i+2] = ""
EndSelect
Next
;*************************************************************************************
; Remove empty items
;*************************************************************************************
for $i = (UBound($CodeArray) - 1) to 1 step -1
if $CodeArray[$i] = "" then _ArrayDelete($CodeArray,$i)
Next
;*************************************************************************************
; Concatenate C number pairs
;*************************************************************************************
$i = 1
While $i <= (UBound($CodeArray) - 1)
if $CodeArray[$i] = "" Then
$i += 1
do
if $CodeArray[$i] = "" then
$i += 1
Else
$CodeArray[$i] &= $CodeArray[$i + 1]
$CodeArray[$i + 1] = ""
$i += 1
EndIf
Until $i = (UBound($CodeArray) - 1) Or $CodeArray[$i] = "" or $CodeArray[$i + 1] = ""
EndIf
$i += 1
WEnd
;*************************************************************************************
; Remove empty items
;*************************************************************************************
for $i = (UBound($CodeArray) - 1) to 1 step -1
if $CodeArray[$i] = "" then _ArrayDelete($CodeArray,$i)
Next
;*************************************************************************************
; Replace Items with 128 Code Patterns, and mount checksum
;*************************************************************************************
_ArrayDelete($CodeArray,0) ;important
If $CodeArray = "" Then
$CodeArray = "11010010000"
$SUM = 104
$CodeType = ""
Else
$CodeArray = "11010011100"
$SUM = 105
$CodeType = ""
EndIf
for $i = 1 to (UBound($CodeArray) - 1)
if $CodeArray[$i] = "" Then
$CodeArray[$i] = "10111101110"
$SUM += $i * 100
$CodeType = ""
ContinueLoop
EndIf
if $CodeArray[$i] = "" Then
$CodeArray[$i] = "10111011110"
$SUM += $i * 99
$CodeType = ""
ContinueLoop
EndIf
for $j = 1 to (UBound($array) - 1)
$data = StringSplit($array[$j],"?")
Select
case $CodeType = ""
if $CodeArray[$i] == $data Then
$CodeArray[$i] = $data
$SUM += $i * $data
EndIf
case $CodeType = ""
if $CodeArray[$i] == $data Then
$CodeArray[$i] = $data
$SUM += $i * $data
EndIf
EndSelect
Next
Next
;*************************************************************************************
; Calculate & find checksum item
;*************************************************************************************
$ChecksumItem = Mod($SUM,103)
$data = StringSplit($array[$ChecksumItem + 1],"?")
_ArrayAdd($CodeArray,$data)
;*************************************************************************************
; Add stop item
;*************************************************************************************
_ArrayAdd($CodeArray,"1100011101011")
;*************************************************************************************
; Flatten array
;*************************************************************************************
$CodeArrayString = _ArrayToString($CodeArray,"")
Return $CodeArrayString
EndFunc
func close()
;*************************************************************************************
; Bye bye
;*************************************************************************************
Exit
EndFunc 不错,楼上的比我的先进多了哈。 我晕,看不懂什么意思了. 先开始也想到是barcode了,不过lz要的是图像,好像和那个有点区别 解决,收贴。 解决,收贴。
Netfox 发表于 2011-3-4 22:04 http://www.autoitx.com/images/common/back.gif
图片上怎么加上数字? 的确很棒,我也解决了 图片上怎么加上数字?
sour 发表于 2011-12-1 15:54 http://www.autoitx.com/images/common/back.gif
也想知道数字怎么加上的? 4楼的代码学习了!厉害 回复 4# smartzbs
非常感谢!!!! 回复 4# smartzbs
不错,多谢了,学习下 不錯唷!!! 學習了 {:face (84):}
页:
[1]