export const getImgSrc = (IMG: any) => new Promise(resolve => {
const img = new Image()
img.crossOrigin = ''
img.src = IMG
img.onload = () => {
const canvas = document.createElement('canvas')
canvas.width = img.width
canvas.height = img.height
const ctx = canvas.getContext('2d')
ctx?.drawImage(img, 0, 0, img.width, img.height)
const ext = img.src.substring(img.src.lastIndexOf('.') + 1).toLowerCase()
// eslint-disable-next-line prefer-template
const dataURL = canvas.toDataURL('image/' + ext)
resolve(dataURL)
}
})
js 图片转base64格式
于 2024-03-29 15:58:40 首次发布