toSave() {
html2canvas(‘照片路径’).then(canvas => {
let saveUrl = canvas.toDataURL('image/png')
let aLink = document.createElement('a')
let blob = this.base64ToBlob(saveUrl)
let evt = document.createEvent('HTMLEvents')
evt.initEvent('click', true, true)
aLink.download = '二维码.jpg'
aLink.href = URL.createObjectURL(blob)
aLink.click()
});
},
//这里把图片转base64
base64ToBlob (code) {
let parts = code.split(';base64,')
let contentType = parts[0].split(':')[1]
let raw = window.atob(parts[1])
let rawLength = raw.length
let uInt8Array = new Uint8Array(rawLength)
for (let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i)
}
return new Blob([uInt8Array], {type: contentType})
},
html2canvas 图片转 base64
最新推荐文章于 2024-08-16 16:55:01 发布