46 lines
1.2 KiB
Plaintext
46 lines
1.2 KiB
Plaintext
import BitmapFactory from 'android.graphics.BitmapFactory';
|
|
|
|
export type QrOpt = {
|
|
content:string,
|
|
logo?:string,
|
|
qrSize?:number,
|
|
logoW?:number,
|
|
logoH?:number,
|
|
marign?:number,
|
|
callback:(data:string)=>void
|
|
}
|
|
|
|
export function getQrData (opt:QrOpt):void{
|
|
if(opt.qrSize==null){
|
|
opt.qrSize=300;
|
|
}
|
|
console.log("--------------")
|
|
if(opt.logo==null){
|
|
opt.callback("data:image/jpg;base64,"+QRCodeGenerator.convert(QRCodeGenerator.generateQRCodeWithLogo(opt.content,opt.qrSize!.toInt(),opt.qrSize!.toInt(),(0).toInt(),(0).toInt(),null)));
|
|
}else{
|
|
try{
|
|
var logo= UTSAndroid.getResourcePath(opt.logo!);
|
|
if(opt.logoW==null){
|
|
opt.logoW=50;
|
|
}
|
|
if(opt.logoH==null){
|
|
opt.logoW=50;
|
|
}
|
|
var bitmap= BitmapFactory.decodeFile(logo);
|
|
|
|
opt.callback("data:image/jpg;base64,"+QRCodeGenerator.convert(QRCodeGenerator.generateQRCodeWithLogo(opt.content,opt.qrSize!.toInt(),opt.qrSize!.toInt(),opt.logoW!.toInt(),opt.logoH!.toInt(),bitmap)));
|
|
|
|
}catch(e:Exception){
|
|
opt.callback("data:image/jpg;base64,"+QRCodeGenerator.convert(QRCodeGenerator.generateQRCodeWithLogo(opt.content,opt.qrSize!.toInt(),opt.qrSize!.toInt(),(0).toInt(),(0).toInt(),null)));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|