You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
780 B
29 lines
780 B
export async function convertIcoToPng(file) {
|
|
// 1. 创建ICO的Blob URL
|
|
const icoUrl = URL.createObjectURL(file)
|
|
|
|
// 2. 加载到Image对象
|
|
const img = await new Promise((resolve, reject) => {
|
|
const img = new Image()
|
|
img.onload = () => resolve(img)
|
|
img.onerror = reject
|
|
img.src = icoUrl
|
|
})
|
|
|
|
// 3. 绘制到Canvas
|
|
const canvas = document.createElement('canvas')
|
|
canvas.width = img.width
|
|
canvas.height = img.height
|
|
const ctx = canvas.getContext('2d')
|
|
ctx.drawImage(img, 0, 0)
|
|
|
|
// 4. 转换为PNG
|
|
const pngDataUrl = canvas.toDataURL('image/png')
|
|
URL.revokeObjectURL(icoUrl) // 释放内存
|
|
|
|
return {
|
|
dataUrl: pngDataUrl,
|
|
width: img.width,
|
|
height: img.height
|
|
}
|
|
}
|