如何制作 html-to-image 在 IOS 设备上读取图像

问题描述 投票:0回答:1

我一直在开发一个使用 html-to-image 库将 div 下载为图像的功能。它在 Android 手机上运行良好,但使用 IOS 手机时,它只下载文本并跳过图像。请问我该如何解决这个问题?

这是我的IOS下载功能。

async function IosDownloadImages(){
    try{
        let dataUrl = await htmlToImage.toJpeg(downloadable.current);
        setTimeout(function(){
            console.log(dataUrl)
            setDownloadStage(86);
            const U = document.createElement('a');
            let ran =  randomNumberInRange(0,999);
            U.download = "Image"+ran;
            setDownloadStage(90);
            U.href = dataUrl;
            U.click();
            return "success";
        },2500);
    }catch(e){
        return e;
    }
}
ios reactjs image download html-to-image
1个回答
0
投票

试试这个:

async function IosDownloadImages(){
try{
    let blob = await Promise.all([
        htmlToImage.toBlob(downloadable.current),
        htmlToImage.toBlob(downloadable.current)
    ]).then((res)=>res[1] as Blob);        
    
    setDownloadStage(86);

    const url = window.URL.createObjectURL(blob)
    let ran =  randomNumberInRange(0,999);
    
    
    setDownloadStage(90);
    
    const link = document.createElement('a');
    link.href = url;
    link.download = "Image"+ran;
    link.click();
    

    return "success";
    
}catch(e){
    return e;
}
© www.soinside.com 2019 - 2024. All rights reserved.