Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can 'zoom' a canvas by scaling the canvas context prior to drawing commands to result in items drawn at a larger size, smoothly. For example, see <a href="http://phrogz.net/tmp/canvas_zoom_to_cursor.html" rel="noreferrer">this example of mine</a> that allows you to zoom way in on draw items and see details not available at the default presentation.</p> <p>The problem with browser zooming is that the HTML5 canvas—like a JPG or PNG, and unlike SVG—is based on individual pixels. If you draw a circle in 10 pixels and then tell the browser to zoom it to 50 pixels the browser cannot "invent" data to draw a smooth circle. The best it can do is provide image interpolation to try to make the 'big pixels' look slightly smoother.</p> <p><strong>The Solution</strong></p> <p>With an image, you can take a picture with a lot of pixels (e.g. 1000x800) and tell the browser to display it at a different, smaller size (e.g. 250x200). When the browser zooms in, it <em>has</em> more pixels to display. For example:</p> <pre><code>&lt;img src="1000x800.jpg" style="width:250px; height:200px"&gt; </code></pre> <p>You can do the same with a canvas. The number of pixels of <em>data</em> in the canvas are specified by the <code>height</code> and <code>width</code> attributes (in HTML or JavaScript). You can separately specify the CSS <em>display size</em> (like above) to a smaller size. You don't even need to modify your existing canvas drawing code; simply:</p> <ol> <li>Adjust the <code>height</code> and <code>width</code> of your canvas by a particular factor (e.g. 4),</li> <li>Use CSS to set the display height and width back to the original size, and then</li> <li>Before all other drawing commands, scale up your context with <code>ctx.scale(4,4)</code>.</li> </ol> <p><strong>Edit</strong>: I have created an example of this here:<br> <a href="http://jsfiddle.net/u5QPq/embedded/result/" rel="noreferrer">http://jsfiddle.net/u5QPq/embedded/result/</a> (<a href="http://jsfiddle.net/u5QPq/" rel="noreferrer">code</a>)</p> <p>Here's what it looks like when you zoom in:<br> <img src="https://i.stack.imgur.com/PHF7W.png" alt="enter image description here"></p> <p>As an added bonus, your canvas will also <em>print</em> more smoothly (in case someone is into killing trees).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload