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

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

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

        drawImage 并调整大小为 Canvas

        drawImage and resize to Canvas(drawImage 并调整大小为 Canvas)
          <i id='PwsFT'><tr id='PwsFT'><dt id='PwsFT'><q id='PwsFT'><span id='PwsFT'><b id='PwsFT'><form id='PwsFT'><ins id='PwsFT'></ins><ul id='PwsFT'></ul><sub id='PwsFT'></sub></form><legend id='PwsFT'></legend><bdo id='PwsFT'><pre id='PwsFT'><center id='PwsFT'></center></pre></bdo></b><th id='PwsFT'></th></span></q></dt></tr></i><div id='PwsFT'><tfoot id='PwsFT'></tfoot><dl id='PwsFT'><fieldset id='PwsFT'></fieldset></dl></div>

              <tbody id='PwsFT'></tbody>
                <bdo id='PwsFT'></bdo><ul id='PwsFT'></ul>

                  <legend id='PwsFT'><style id='PwsFT'><dir id='PwsFT'><q id='PwsFT'></q></dir></style></legend>

                • <small id='PwsFT'></small><noframes id='PwsFT'>

                • <tfoot id='PwsFT'></tfoot>
                  本文介绍了drawImage 并调整大小为 Canvas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 1836 x 3264 的图像,我想 drawImage() 到画布上并将大小调整为 739 x 1162.

                  I have an image which is 1836 x 3264 I want to drawImage() to canvas and resize to 739 x 1162.

                  阅读文档后,我认为这可以通过以下方式完成:

                  After reading the documentation I thought this could be accomplished with the following:

                  ctx.drawImage(image, 0, 0, 739, 1162);
                  

                  我也试过了:

                  ctx.drawImage(image, 0, 0, 1836, 3264, 0, 0, 739, 1162);
                  

                  两者都只显示完整图像的一小部分,而不是缩小它.

                  Both show only a small part of the full image instead of shrinking it down.

                  如何传递值以从 1836 x 3264 -> 739 x 1162 调整大小?

                  How do I pass through the values to resize from 1836 x 3264 -> 739 x 1162 ?

                  推荐答案

                  你看到的东西是正确的,所以你可能会仔细检查某个地方的错字.

                  What you have looks correct, so you might double-check for a typo somewhere.

                  [额外的想法:你的图像真的是 1836x3264 而不是 3264x1836.]

                  [additional thought: Is your image really 1836x3264 and not 3264x1836.]

                  这是工作代码和小提琴:http://jsfiddle.net/m1erickson/MLGr4/

                  Here is working code and a Fiddle: http://jsfiddle.net/m1erickson/MLGr4/

                  <!doctype html>
                  <html>
                  <head>
                  <link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
                  <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
                  
                  <style>
                      body{ background-color: ivory; }
                      canvas{border:1px solid red;}
                  </style>
                  
                  <script>
                  $(function(){
                  
                      var canvas=document.getElementById("canvas");
                      var ctx=canvas.getContext("2d");
                  
                      img=new Image();
                      img.onload=function(){
                          canvas.width=400;
                          canvas.height=300;
                          ctx.drawImage(img,0,0,img.width,img.height,0,0,400,300);
                      }
                      img.src="http://www.onestopwebmasters.com/wp-content/uploads/2011/06/eitai-bridge.jpg";
                  
                  }); // end $(function(){});
                  </script>
                  
                  </head>
                  
                  <body>
                      <canvas id="canvas" width=100 height=100></canvas>
                  </body>
                  </html>
                  

                  这篇关于drawImage 并调整大小为 Canvas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How does object-fit work with canvas element?(对象适合如何与画布元素一起使用?)
                  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(我想沿特定路径对对象进行动画处理)
                    <i id='bQmDk'><tr id='bQmDk'><dt id='bQmDk'><q id='bQmDk'><span id='bQmDk'><b id='bQmDk'><form id='bQmDk'><ins id='bQmDk'></ins><ul id='bQmDk'></ul><sub id='bQmDk'></sub></form><legend id='bQmDk'></legend><bdo id='bQmDk'><pre id='bQmDk'><center id='bQmDk'></center></pre></bdo></b><th id='bQmDk'></th></span></q></dt></tr></i><div id='bQmDk'><tfoot id='bQmDk'></tfoot><dl id='bQmDk'><fieldset id='bQmDk'></fieldset></dl></div>

                      <tbody id='bQmDk'></tbody>

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

                          <legend id='bQmDk'><style id='bQmDk'><dir id='bQmDk'><q id='bQmDk'></q></dir></style></legend>
                            <bdo id='bQmDk'></bdo><ul id='bQmDk'></ul>
                            <tfoot id='bQmDk'></tfoot>