Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用浏览器文件系统API创建IMG_Javascript_Browser_Browser Nativefs - Fatal编程技术网

Javascript 如何使用浏览器文件系统API创建IMG

Javascript 如何使用浏览器文件系统API创建IMG,javascript,browser,browser-nativefs,Javascript,Browser,Browser Nativefs,在客户端,如何使用本机浏览器文件系统API在IMG元素中嵌入base64图像数据 function createIMGFromFS () { var img = document.createElement("img"); const openFile = async () => { const [fh] = await window.showOpenFilePicker(); var file2 = await fh.getFile();

在客户端,如何使用本机浏览器文件系统API在IMG元素中嵌入base64图像数据

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;
}