概述将粘贴的图像持久化便于离线与编辑。本文示例读取图像并写入 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; } } } }

发表评论 取消回复