/ Published in: JavaScript
Somewhere along the road the people behind canvas decided that all image scaling is anti-aliased by default. Firefox has 'mozImageSmoothingEnabled' while Chrome et company don't.
This is a proof of concept script to resize 'virtualCanvas' two times and draw it on 'targetCanvas' w/o any antialiasing.
Proof of concept in that it still takes too long to compute in real time.
- Firefox: 1ms with native antialiasing off
- Chrome: 45ms with the script below
It might be useful to use this to scale assets before doing any compositioning. Like, load images, scale them up, position everything times two... But if yer planning to composite the canvas first and scale that to fit as the last step, I'd advice against it..
This is a proof of concept script to resize 'virtualCanvas' two times and draw it on 'targetCanvas' w/o any antialiasing.
Proof of concept in that it still takes too long to compute in real time.
- Firefox: 1ms with native antialiasing off
- Chrome: 45ms with the script below
It might be useful to use this to scale assets before doing any compositioning. Like, load images, scale them up, position everything times two... But if yer planning to composite the canvas first and scale that to fit as the last step, I'd advice against it..
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var targetContext = targetCanvas.getContext("2d") var h, w, hV = virtualCanvas.height, wV = virtualCanvas.width, h2, w2 for (h = 0; h < hV; h++) { h2 = h * 2 for (w = 0; w < wV; w++) { w2 = w * 2 targetContext.drawImage( this.virtualCanvas, w, h, 1, 1, w2, h2, 2, 2 ) } }