-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQRCodes.bbj
53 lines (39 loc) · 2.07 KB
/
QRCodes.bbj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use com.google.zxing.BarcodeFormat
use com.google.zxing.WriterException
use com.google.zxing.client.j2se.MatrixToImageWriter
use com.google.zxing.common.BitMatrix
use com.google.zxing.qrcode.QRCodeWriter
use java.io.ByteArrayOutputStream
class public QRCodes
method public static byte[] getQRCode(BBjString string$, BBjNumber width, BBjNumber height)
if string$="" then
let string$=" "
endif
c! = Class.forName("com.google.zxing.qrcode.QRCodeWriter",err=*next)
if c! = null() then
classloader! = new com.basiscomponents.util.JarLoader(err=classpath_err)
classloader!.addFile(BBjAPI().getFileSystem().resolvePath("QRCodes/lib/core-3.3.0.jar"))
classloader!.addFile(BBjAPI().getFileSystem().resolvePath("QRCodes/lib/javase-3.3.0.jar"))
c! = classloader!.loadClass("com.google.zxing.qrcode.QRCodeWriter")
bf! = classloader!.loadClass("com.google.zxing.BarcodeFormat")
mx! = classloader!.loadClass("com.google.zxing.client.j2se.MatrixToImageWriter")
else
bf! = Class.forName("com.google.zxing.BarcodeFormat")
mx! = Class.forName("com.google.zxing.client.j2se.MatrixToImageWriter")
endif
qrCodeWriter! = c!.newInstance()
bitMatrix! = qrCodeWriter!.encode(string$, bf!.getDeclaredField("QR_CODE").get(null()), width, height)
ms! = mx!.getMethods()
for i=0 to ms!.length-1
method! = ms![i]
if method!.getName() = "writeToStream" and method!.getParameterCount() = 3 then
break
endif
next
pngOutputStream! = new ByteArrayOutputStream()
method!.invoke(new Object(), bitMatrix!, "PNG", pngOutputStream!)
methodret pngOutputStream!.toByteArray()
classpath_err:
throw "Add the two .jar files in the lib subfolder of this plugin to your classpath or update to a recent 19.20ff BBj version so they can be loaded dynamically!",252
methodend
classend