Comments (5)
Seems like on resize you'll want to trigger a redraw, if you re-call .getContext('2d')
it should adjust the dimensions accordingly.
Though specifically this is definitely outside the scope of the tool.
from hidpi-canvas-polyfill.
Doesn't seem to have any effect :/
/* previous code... */
//causing the trouble
$('#thing').attr('width',$('#thing').parent().width());
ctx = $('#thing').get(0).getContext("2d");
from hidpi-canvas-polyfill.
What about this?
var ctx = $('#thing').get(0).getContext("2d");
ctx.beginPath();
ctx.arc(150, 150, 100, 0, 2* Math.PI, false);
ctx.strokeStyle = "red";
ctx.lineWidth = 40;
ctx.stroke();
//causing the trouble
$('#thing').attr('width',$('#thing').parent().width());
// now actually redraw stuff
var ctx = $('#thing').get(0).getContext("2d");
ctx.beginPath();
ctx.arc(150, 150, 100, 0, 2* Math.PI, false);
ctx.strokeStyle = "red";
ctx.lineWidth = 40;
ctx.stroke();
Though you probably need to clear the canvas before redrawing.
from hidpi-canvas-polyfill.
I isolated it a bit. This is resulting in a quarter circle on a 2x device but normal on a 1x device.
<canvas id="thing" height="300" width="300"></canvas>
<script>
document.getElementById('thing').setAttribute('width',100);
document.getElementById('thing').setAttribute('height',100);
var ctx = document.getElementById('thing').getContext("2d");
ctx.beginPath();
ctx.arc(ctx.canvas.width/2, ctx.canvas.height/2,
ctx.canvas.width/4, 0, 2* Math.PI, false);
ctx.strokeStyle = "red";
ctx.lineWidth = ctx.canvas.width/6;
ctx.stroke();
</script>
Off topic; but I actually think browsers should handle all of this.
from hidpi-canvas-polyfill.
Sooooo, I believe what is happening is that you're using the canvas.height
and canvas.width
to calculate the inputs here.
In the polyfill, I modify these values behind the scenes so they are actually double what you expect, and the canvas is sized via css back to it's expected size, which produces the retina sharpness.
For example if you replace ctx.canvas.width
and ctx.canvas.height
with 300
, everything works as expected.
If you need to base your calculations on the canvas height/width, you can use the function I provide in the README to get the pixel ratio so you can scale these appropriately as well
from hidpi-canvas-polyfill.
Related Issues (20)
- Do nothing if pixel ratio is 1 HOT 3
- Stroke lineWidth bug HOT 3
- Safari console error HOT 4
- How to tell if polyfill has been used? HOT 1
- How do you resize the canvas? HOT 6
- Subsequent calls to `canvas.getContext('2d')` results in exponential growth of width and height HOT 6
- is there something wrong when drawImage? HOT 1
- It seem that there is no processing for drawImage HOT 5
- problem on idevice iphone ipad HOT 2
- ios10 has bug #17 HOT 1
- Successive calls to getContext('2d') keeps scaling up the canvas HOT 2
- isPointInPath sometimes returns wrong value HOT 2
- Privacy Badger by EFF, Library not working with extension enabled!
- support enable/disable
- Add default implementation for drawImage HOT 2
- Support webpack and similar web bundlers HOT 2
- iPad issues
- Android devices fps is too slow now.
- There is no mechanism for resize handling. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hidpi-canvas-polyfill.