<small id='vpQr2'></small><noframes id='vpQr2'>

  • <tfoot id='vpQr2'></tfoot>
      <bdo id='vpQr2'></bdo><ul id='vpQr2'></ul>
    <i id='vpQr2'><tr id='vpQr2'><dt id='vpQr2'><q id='vpQr2'><span id='vpQr2'><b id='vpQr2'><form id='vpQr2'><ins id='vpQr2'></ins><ul id='vpQr2'></ul><sub id='vpQr2'></sub></form><legend id='vpQr2'></legend><bdo id='vpQr2'><pre id='vpQr2'><center id='vpQr2'></center></pre></bdo></b><th id='vpQr2'></th></span></q></dt></tr></i><div id='vpQr2'><tfoot id='vpQr2'></tfoot><dl id='vpQr2'><fieldset id='vpQr2'></fieldset></dl></div>

    1. <legend id='vpQr2'><style id='vpQr2'><dir id='vpQr2'><q id='vpQr2'></q></dir></style></legend>

        将 base64 png 数据转换为 javascript 文件对象

        时间:2023-10-01
          <tbody id='ILoHg'></tbody>

        <small id='ILoHg'></small><noframes id='ILoHg'>

        <legend id='ILoHg'><style id='ILoHg'><dir id='ILoHg'><q id='ILoHg'></q></dir></style></legend>
          <tfoot id='ILoHg'></tfoot>

                <i id='ILoHg'><tr id='ILoHg'><dt id='ILoHg'><q id='ILoHg'><span id='ILoHg'><b id='ILoHg'><form id='ILoHg'><ins id='ILoHg'></ins><ul id='ILoHg'></ul><sub id='ILoHg'></sub></form><legend id='ILoHg'></legend><bdo id='ILoHg'><pre id='ILoHg'><center id='ILoHg'></center></pre></bdo></b><th id='ILoHg'></th></span></q></dt></tr></i><div id='ILoHg'><tfoot id='ILoHg'></tfoot><dl id='ILoHg'><fieldset id='ILoHg'></fieldset></dl></div>

                  <bdo id='ILoHg'></bdo><ul id='ILoHg'></ul>
                  本文介绍了将 base64 png 数据转换为 javascript 文件对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个用 PNG 编码的 base64,我需要使用 比较它们Resemble.JS

                  I have two base64 encoded in PNG, and I need to compare them using Resemble.JS

                  我认为最好的方法是使用 fileReaderPNG 转换为文件对象.我该怎么做?

                  I think that the best way to do it is to convert the PNG's into file objects using fileReader. How can I do it?

                  推荐答案

                  你可以从你的base64数据创建一个Blob,然后读取它asDataURL:

                  You can create a Blob from your base64 data, and then read it asDataURL:

                  var img_b64 = canvas.toDataURL('image/png');
                  var png = img_b64.split(',')[1];
                  
                  var the_file = new Blob([window.atob(png)],  {type: 'image/png', encoding: 'utf-8'});
                  
                  var fr = new FileReader();
                  fr.onload = function ( oFREvent ) {
                      var v = oFREvent.target.result.split(',')[1]; // encoding is messed up here, so we fix it
                      v = atob(v);
                      var good_b64 = btoa(decodeURIComponent(escape(v)));
                      document.getElementById("uploadPreview").src = "data:image/png;base64," + good_b64;
                  };
                  fr.readAsDataURL(the_file);
                  

                  完整示例(包括垃圾代码和控制台日志):http://jsfiddle.net/tTYb8/一个>

                  或者,您可以使用 .readAsText,它可以正常工作,而且更优雅.. 但由于某种原因 text 听起来不对 ;)

                  Alternatively, you can use .readAsText, it works fine, and its more elegant.. but for some reason text does not sound right ;)

                  fr.onload = function ( oFREvent ) {
                      document.getElementById("uploadPreview").src = "data:image/png;base64,"
                      + btoa(oFREvent.target.result);
                  };
                  fr.readAsText(the_file, "utf-8"); // its important to specify encoding here
                  

                  完整示例:http://jsfiddle.net/tTYb8/3/

                  这篇关于将 base64 png 数据转换为 javascript 文件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何下载 base64 编码的图像? 下一篇:将 Web 字体转换和渲染为 base64 - 保持原始外观

                  相关文章

                  • <bdo id='pE1yO'></bdo><ul id='pE1yO'></ul>

                  <small id='pE1yO'></small><noframes id='pE1yO'>

                  <tfoot id='pE1yO'></tfoot>

                  1. <i id='pE1yO'><tr id='pE1yO'><dt id='pE1yO'><q id='pE1yO'><span id='pE1yO'><b id='pE1yO'><form id='pE1yO'><ins id='pE1yO'></ins><ul id='pE1yO'></ul><sub id='pE1yO'></sub></form><legend id='pE1yO'></legend><bdo id='pE1yO'><pre id='pE1yO'><center id='pE1yO'></center></pre></bdo></b><th id='pE1yO'></th></span></q></dt></tr></i><div id='pE1yO'><tfoot id='pE1yO'></tfoot><dl id='pE1yO'><fieldset id='pE1yO'></fieldset></dl></div>
                  2. <legend id='pE1yO'><style id='pE1yO'><dir id='pE1yO'><q id='pE1yO'></q></dir></style></legend>