Don't multiply by the device pixel ratio if that will put us over the canvas limit

This commit is contained in:
Maurice Parker 2020-05-06 14:55:34 -05:00
parent 5f60b84b8b
commit 502ff3e019
1 changed files with 7 additions and 3 deletions

View File

@ -35,10 +35,14 @@ class ImageViewer {
this.hideLoadingIndicator();
var canvas = document.createElement("canvas");
canvas.width = this.img.naturalWidth * window.devicePixelRatio;
canvas.height = this.img.naturalHeight * window.devicePixelRatio;
var pixelRatio = window.devicePixelRatio;
do {
canvas.width = this.img.naturalWidth * pixelRatio;
canvas.height = this.img.naturalHeight * pixelRatio;
pixelRatio--;
} while (pixelRatio > 0 && canvas.width * canvas.height > 16777216)
canvas.getContext("2d").drawImage(this.img, 0, 0, canvas.width, canvas.height);
const rect = this.img.getBoundingClientRect();
const message = {
x: rect.x,