如何使用浏览器文件系统API创建IMG [英] How to use browser file system API to create an IMG
本文介绍了如何使用浏览器文件系统API创建IMG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在客户端,如何使用本机浏览器文件系统API在IMG元素中嵌入base64图像数据?
On the client side, how can I use the native browser filesystem API to embed base64 image data within an IMG element?
推荐答案
function createIMGFromFS () {
var img = document.createElement("img");
const openFile = async () => {
const [fh] = await window.showOpenFilePicker();
var file2 = await fh.getFile();
var name = file2.name;
var fr = new FileReader();
fr.readAsDataURL(file2);
fr.onloadend = function() {
img.src = fr.result;
}
}
const file = openFile();
return img;
}
这篇关于如何使用浏览器文件系统API创建IMG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文