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

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

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

      1. <tfoot id='E0kOw'></tfoot>
          <bdo id='E0kOw'></bdo><ul id='E0kOw'></ul>

        将图像转换为已加载的画布

        Convert an image to canvas that is already loaded(将图像转换为已加载的画布)
          <i id='TcTlO'><tr id='TcTlO'><dt id='TcTlO'><q id='TcTlO'><span id='TcTlO'><b id='TcTlO'><form id='TcTlO'><ins id='TcTlO'></ins><ul id='TcTlO'></ul><sub id='TcTlO'></sub></form><legend id='TcTlO'></legend><bdo id='TcTlO'><pre id='TcTlO'><center id='TcTlO'></center></pre></bdo></b><th id='TcTlO'></th></span></q></dt></tr></i><div id='TcTlO'><tfoot id='TcTlO'></tfoot><dl id='TcTlO'><fieldset id='TcTlO'></fieldset></dl></div>

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

            1. <tfoot id='TcTlO'></tfoot>
                <tbody id='TcTlO'></tbody>

                • <bdo id='TcTlO'></bdo><ul id='TcTlO'></ul>
                  <legend id='TcTlO'><style id='TcTlO'><dir id='TcTlO'><q id='TcTlO'></q></dir></style></legend>
                  本文介绍了将图像转换为已加载的画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个插件,在该插件中我将图像转换为画布并存储为数据 url.此函数触发加载"事件,但如何转换页面上已经存在的图像?(不想刷新页面或再次加载任何图像).我尝试使用 Filereader() 函数,但这也适用于onload"概念.那么如何在用户点击图片时将图片保存为数据url呢?

                  I am working on a plugin in which I'm converting Image into Canvas and storing as data url .This function triggers on 'load' event but how can I convert an image which is already there on the page? (Don't want to refresh the page or load any image again). I tried using the Filereader() function but that also works on 'onload' concept. So how can I save the image as data url when the user clicks on the image?

                     image.addEventListener("load", function () {
                  
                           var imgCanvas = document.createElement("canvas"),
                              imgContext = imgCanvas.getContext("2d");
                              imgCanvas.width = image.width;
                              imgCanvas.height = image.height;
                  
                              imgContext.drawImage(image, 0, 0, image.width, image.height);       
                              imgInfo = imgCanvas.toDataURL("image/png");
                  
                              localStorage.setItem("imgInfo", imgInfo);
                          }, false);
                  

                  推荐答案

                  现在完美运行.如果您使用 javascript 创建临时图像元素,然后将其存储在 localStorage 中.这对我有用,希望它也能帮助其他人

                  Now it works perfectly.If you create a temporary image element using javascript then store it in localStorage. This worked for me hope it'll help others too

                      image = document.createElement('img');
                      document.body.appendChild(image);
                      image.setAttribute('style','display:none');
                      image.setAttribute('alt','script div');
                      image.setAttribute("src", path);
                  
                      var imgCanvas = document.createElement("canvas"),
                      imgContext = imgCanvas.getContext("2d");
                  
                      // Make sure canvas is as big as the picture
                      imgCanvas.width = image.width;
                      imgCanvas.height = image.height;
                  
                      // Draw image into canvas element
                      imgContext.drawImage(image, 0, 0, image.width, image.height);
                      // Save image as a data URL
                      imgInfom = imgCanvas.toDataURL("image/png");
                      localStorage.setItem("imgInfo",imgInfom);
                      document.body.removeChild(image);
                  

                  这篇关于将图像转换为已加载的画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))

                      • <bdo id='77t3t'></bdo><ul id='77t3t'></ul>

                        <small id='77t3t'></small><noframes id='77t3t'>

                          <legend id='77t3t'><style id='77t3t'><dir id='77t3t'><q id='77t3t'></q></dir></style></legend>
                            <tbody id='77t3t'></tbody>

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