概述将粘贴的图像持久化便于离线与编辑。本文示例读取图像并写入 OPFS。粘贴与保存async function saveClipboardImage() { const items = await navigator.clipboard.read(); for (const it of items) { for (const t of it.types) { if (t.startsWith('image/')) { const blob = await it.getType(t); const root = await navigator.storage.getDirectory(); const name = `paste-${Date.now()}.png`; const fh = await root.getFileHandle(name, { create: true }); const w = await fh.createWritable(); await w.write(await blob.arrayBuffer()); await w.close(); return name; } } } }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.907927s