0.0.1 • Published 5 years ago

cordova-plugin-bitmap v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

base64ͼƬתZPLָ����

async printImg() { var that = this printer.bitmap.setThreshold(125, function (success) { }, function (error) { });//��ֵ //5000����ͼ���������ֽ���:height * width / 8; 25�����е��ֽ���width / 8 var awidth = window.getComputedStyle(document.querySelector('#imgPrint')).width var aheight = window.getComputedStyle(document.querySelector('#imgPrint')).height var nbWidth = parseInt(awidth.slice(0, awidth.length - 2)) var nbHeight = parseInt(aheight.slice(0, aheight.length - 2))

var newImageData = this.imgPath
console.log(newImageData.slice(1, 50))
var scale = 1;
var tt = 568; //�����
if (nbWidth > tt) {
  scale = 568 / nbWidth

  nbWidth = 568   //������Ϊ568px
  nbHeight = Math.ceil(nbHeight * scale) //����߶����ź�
  var imgObj = document.getElementById("imgPrint");
  newImageData = this.canvasCompress(imgObj, nbWidth, nbHeight, 0.8)
}
let imgUrl = newImageData.slice(23)
console.log(newImageData.slice(1, 50))
if (nbWidth % 8 != 0) {   //����ֽ���Ҫ��8����
  nbWidth = (Math.floor((nbWidth / 8)) + 1) * 8
}

var a5000 = nbWidth * nbHeight / 8  //�������ֽ��� height * width / 8
var a25 = nbWidth / 8   //���㵥���ֽ��� width / 8
var c = "^XA~DGR:LOGO.GRF," + a5000.toString() + "," + a25.toString() + ",";
var b = new Uint8Array(c.length);
for (let i = 0; i < c.length; i++) {
  b[i] = c.charCodeAt(i);
}
var path16
printer.bitmap.analysisB64ToZ64(imgUrl, function (success) {
  path16 = new Uint8Array(success);
  var e = "^FO" + 0 + "," + 0 + "^XGR:LOGO.GRF,1,1^FS^PQ1,0,1,Y^XZ"
  var w = new Uint8Array(e.length);

  for (let i = 0; i < e.length; i++) {
    w[i] = e.charCodeAt(i);
  }

  DSPrinter.writeCmd(b, that.succCallback, that.failCallback);
  DSPrinter.writeCmd(path16, that.succCallback, that.failCallback)
  DSPrinter.writeCmd(w, that.succCallback, that.failCallback)

}, function (err) {
});
//let path16 = this.strToHexCharCode(this.imgPath.slice(23))

}