<legend id='dj4kJ'><style id='dj4kJ'><dir id='dj4kJ'><q id='dj4kJ'></q></dir></style></legend>
      <bdo id='dj4kJ'></bdo><ul id='dj4kJ'></ul>
  1. <tfoot id='dj4kJ'></tfoot>

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

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

    1. 我如何知道 HTML5 Canvas 的渲染何时完成?

      How do I know when HTML5 Canvas#39; Rendering is Finished?(我如何知道 HTML5 Canvas 的渲染何时完成?)
    2. <small id='N3LVr'></small><noframes id='N3LVr'>

      <tfoot id='N3LVr'></tfoot>
        <tbody id='N3LVr'></tbody>

          1. <i id='N3LVr'><tr id='N3LVr'><dt id='N3LVr'><q id='N3LVr'><span id='N3LVr'><b id='N3LVr'><form id='N3LVr'><ins id='N3LVr'></ins><ul id='N3LVr'></ul><sub id='N3LVr'></sub></form><legend id='N3LVr'></legend><bdo id='N3LVr'><pre id='N3LVr'><center id='N3LVr'></center></pre></bdo></b><th id='N3LVr'></th></span></q></dt></tr></i><div id='N3LVr'><tfoot id='N3LVr'></tfoot><dl id='N3LVr'><fieldset id='N3LVr'></fieldset></dl></div>
          2. <legend id='N3LVr'><style id='N3LVr'><dir id='N3LVr'><q id='N3LVr'></q></dir></style></legend>
              • <bdo id='N3LVr'></bdo><ul id='N3LVr'></ul>
                本文介绍了我如何知道 HTML5 Canvas 的渲染何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                html:

                <canvas id="cnv" width="786" height="1113">
                

                js:

                var img = new Image(),
                    cnv = document.getElementById('cnv');
                
                var context = cnv.getContext('2d');
                
                img.onload = function () {
                
                    context.drawImage(img, 0, 0, 786, 1113);
                    alert('finished drawing');
                
                }
                
                img.src = 'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white_fe6da1ec.png';
                

                http://jsfiddle.net/FxrSa/14/

                我想在画布完成渲染后显示警报.但是在绘制图像之前会显示警报.

                I want to show the alert after the canvas finished his rendering. But the alert show before the image is drawn.

                如何等待 GUI 线程完成他的渲染?

                How can I wait for the GUI thread to finish his rendering?

                推荐答案

                Canvas drawImage 是同步的.甚至,真正同步.

                Canvas drawImage is synchronous. And even, really synchronous.

                您的问题是 alert() 正在阻塞,甚至是真正阻塞.

                Your problem is that alert() is blocking, and even really blocking.

                我的意思是它不仅会阻止 js 执行,还会阻止页面渲染.所以浏览器已经在你的画布上绘制了你的图像,但是当你调用 alert() 时还没有显示它.

                By this I mean it does not only block the js execution, it also blocks the page rendering. So the browser has painted your image on your canvas, but didn't display it yet when you called alert().

                应始终避免使用 alert 并将其替换为普通的 DOM 元素.

                One should always avoid alert and replace it with normal DOM elements.

                Ps:这是一个证据,您的图像确实已经绘制在画布上.

                Ps: Here is a proof that your image is indeed already painted on the canvas.

                这篇关于我如何知道 HTML5 Canvas 的渲染何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                <tfoot id='HeFYj'></tfoot>
                <legend id='HeFYj'><style id='HeFYj'><dir id='HeFYj'><q id='HeFYj'></q></dir></style></legend>
                • <bdo id='HeFYj'></bdo><ul id='HeFYj'></ul>

                    <tbody id='HeFYj'></tbody>

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

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