var image = new Image();
//image.setAttribute('crossOrigin', 'anonymous');
//image.crossOrigin="anonymous"; //关键
image.src = fileSrc;
plus.nativeUI.showWaiting('打水印中');
image.onload = function() {
//var canvasD = document.getElementById('photo8888');
var canvasD = document.createElement('canvas');
console.log("加载水印");
console.log(this.width + '####' + this.height);
var originWidth = this.width;
var originHeight = this.height;
// 最大尺寸限制,可通过国设置宽高来实现图片压缩程度
var maxWidth = 800;
var maxHeight = 800;
// 目标尺寸
var targetWidth = originWidth;
var targetHeight = originHeight;
// 图片尺寸超过400x400的限制
if (originWidth > maxWidth || originHeight > maxHeight) {
if (originWidth / originHeight > maxWidth / maxHeight) {
// 更宽,按照宽度限定尺寸
targetWidth = maxWidth;
targetHeight = Math.round(maxWidth * (originHeight / originWidth));
} else {
targetHeight = maxHeight;
targetWidth = Math.round(maxHeight * (originWidth / originHeight));
}
}
console.log(targetWidth + '####' + targetHeight);
canvasD.width = targetWidth;
canvasD.height = targetHeight;
var ctx = canvasD.getContext("2d");
//ctx.clearRect(0, 0, targetWidth, targetHeight);
ctx.drawImage(this, 0, 0, canvasD.width, canvasD.height);
//绘制水印
// ctx.font = "bolder 32px microsoft yahei";
ctx.font = "bold 20px Arial"
ctx.fillStyle = "rgba(254,61,55,1)";
var lineHeight = 32;
var chaCount = 10;
var starHeight = 40;
var totalHeight = targetHeight - 5;
var hang = 0;
var len = parseInt(targetWidth * 24 / 694) * 2;
var canLen = len * 2;
console.log('一行的文字数量:' + len);
if (dataShuiyin.address) {
if (dataShuiyin.address.length > len) {
hang = 1;
} else {
hang = 0;
}
writeTextOnCanvas(ctx, lineHeight, canLen, dataShuiyin.address, 2, totalHeight - hang * lineHeight);
}
//ctx.fillText(dataShuiyin.address,2,totalHeight - hang * lineHeight) ;
//经纬度
ctx.fillText(dataShuiyin.longlat, 2, totalHeight - (hang + 1) * lineHeight);
//营业厅
ctx.fillText(dataShuiyin.yingValue, 2, totalHeight - (hang + 2) * lineHeight);
//终端编号
ctx.fillText(dataShuiyin.temalValue, 2, totalHeight - (hang + 3) * lineHeight);
//console.log('4**' + canvasD.toDataURL('image/jpeg', 0.92));
cover.attr('src', canvasD.toDataURL('image/jpeg', 0.92));
}
手写的从前
我也遇到了这个问题,不是内存不足,我回退到上个版本就没问题,一更新 就不行了 提示 “_downloads/Unknown”
2019-10-14 20:59
手写的从前
希望能解决一下
2019-10-14 20:59
手写的从前
2.3.2 一点问题都没
2019-10-14 21:00