注册 登录
编程论坛 VFP论坛

字串转二维码,简单易用,无乱码

sych 发布于 2023-06-17 20:10, 953 次点击
DECLARE FullQRCode IN "QRCodeLib.dll" ;
    INTEGER lAutoConfigurate, ;
    INTEGER lAutoFit, ;
    LONG nBackColor, ;
    LONG nBarColor, ;
    STRING cText, ;
    INTEGER nCorrectionLevel, ;
    INTEGER nEncoding, ;
    INTEGER nMarginPixels, ;
    INTEGER nModuleWidth, ;
    INTEGER nHeight, ;
    INTEGER nWidth, ;
    STRING cFileName

m.lAutoConfigurate = .T.
m.lAutoFit = .T.
m.nBackColor = RGB(255, 255, 255) && White
m.nBarColor = RGB(0, 0, 0) && Black
m.nCorrectionLevel = 1 && 0-[L]ow 7%, 1-[M]edium 15%, 2-[Q]uartile 25%, 3-[H]igh 30%]
m.nEncoding = 4 && Automatic encoding algorithm
m.nMarginPixels = 0 && pixels
m.nModuleWidth = 2 && pixels
m.nHeight = 132 && pixels
m.nWidth = 132 && pixels
m.tcText="123中国123中国123中国123中国123中国123中国123中国"
m.tcFile="1.bmp"

FullQRCode(m.lAutoConfigurate, m.lAutoFit, m.nBackColor, m.nBarColor, ;
    m.tcText, m.nCorrectionLevel, m.nEncoding, m.nMarginPixels, ;
    m.nModuleWidth, m.nHeight, m.nWidth, m.tcFile)

QRCodeLib.dll文件是https://里面的文件
只有本站会员才能查看附件,请 登录
7 回复
#2
schtg2023-06-18 04:52
谢谢分享!
#3
sam_jiang2023-06-18 12:33
foxbarcode也有一个二维码,使用很简单。

借楼主的贴分享一下,里面有例子:
程序代码:

*--------------------------------------------------------------------------------------
* Example1.prg
*--------------------------------------------------------------------------------------
* FoxBarcodeQR example form
*--------------------------------------------------------------------------------------

SET PROCEDURE TO LOCFILE("FoxBarcodeQR.prg") ADDITIVE

*--- Create FoxBarcodeQR object and QR Code barcode image
LOCAL loFbc, lcQRImage
m.loFbc = CREATEOBJECT("FoxBarcodeQR")
m.lcQRImage = m.loFbc.QRBarcodeImage("https:///VFPX/FoxBarcode", , 6, 2)

*-- Create form
LOCAL loForm AS FORM
m.loForm = CREATEOBJECT("Form")
WITH m.loForm
.CAPTION = "FoxBarcodeQR example form"
.WIDTH = 400
.HEIGHT = 400
.BACKCOLOR = RGB(255,255,255)
.AUTOCENTER = .T.
.ADDOBJECT("Image1", "Image")
WITH .Image1
  .PICTURE = m.lcQRImage
  .TOP = 20
  .LEFT = 20
  .VISIBLE = .T.
ENDWITH
.SHOW(1)
ENDWITH

m.loForm = NULL
m.loFbc = NULL



只有本站会员才能查看附件,请 登录


[此贴子已经被作者于2023-6-18 14:22编辑过]

#4
schtg2023-06-18 16:46
回复 3楼 sam_jiang
谢谢!
#5
sych2023-06-18 20:27
上面的代码没有经过充分测试,还是有BUG,在最后添加一句为好
m.tcText=iif(left(m.tcText,3)==0hEFBBBF,m.tcText,0hEFBBBF+STRCONV(m.tcText,9))
完整代码如下:
DECLARE FullQRCode IN "QRCodeLib.dll" ;
    INTEGER lAutoConfigurate, ;
    INTEGER lAutoFit, ;
    LONG nBackColor, ;
    LONG nBarColor, ;
    STRING cText, ;
    INTEGER nCorrectionLevel, ;
    INTEGER nEncoding, ;
    INTEGER nMarginPixels, ;
    INTEGER nModuleWidth, ;
    INTEGER nHeight, ;
    INTEGER nWidth, ;
    STRING cFileName

m.lAutoConfigurate = .t.
m.lAutoFit = .t.
m.nBackColor = RGB(255,255,255) && White
m.nBarColor = RGB(0, 0, 0) && Black
m.nCorrectionLevel = 1 && 0-[L]ow 7%, 1-[M]edium 15%, 2-[Q]uartile 25%, 3-[H]igh 30%]
m.nEncoding = 4 && Automatic encoding algorithm
m.nMarginPixels = 0 && pixels
m.nModuleWidth = 2 && pixels
m.nWidth = 500 && pixels
m.nHeight = m.nWidth && pixels
m.tcText=repl("中",5)
m.tcFile="1.bmp"
m.tcText=iif(left(m.tcText,3)==0hEFBBBF,m.tcText,0hEFBBBF+STRCONV(m.tcText,9))

FullQRCode(m.lAutoConfigurate, m.lAutoFit, m.nBackColor, m.nBarColor, ;
    m.tcText, m.nCorrectionLevel, m.nEncoding, m.nMarginPixels, ;
    m.nModuleWidth, m.nHeight, m.nWidth, m.tcFile)

还有这三个参数不知道什么意思,有知道的朋友请不吝赐教
m.lAutoConfigurate = .t.
m.lAutoFit = .t.
m.nEncoding = 4 && Automatic encoding algorithm
#6
zhken2023-06-18 22:45
谢谢分享
#7
kangss2023-06-19 18:29
感谢分享!
#8
yangdi昨天 14:52
汉字基本是乱码
1