scale up and round to avoid rounding errors
This commit is contained in:
@@ -135,10 +135,19 @@ class Static extends ImageSource {
|
|||||||
imageWidth = image.width;
|
imageWidth = image.width;
|
||||||
imageHeight = image.height;
|
imageHeight = image.height;
|
||||||
}
|
}
|
||||||
const resolution = getHeight(imageExtent) / imageHeight;
|
const extentWidth = getWidth(imageExtent);
|
||||||
const targetWidth = Math.ceil(getWidth(imageExtent) / resolution);
|
const extentHeight = getHeight(imageExtent);
|
||||||
if (targetWidth != imageWidth) {
|
const xResolution = extentWidth / imageWidth;
|
||||||
const context = createCanvasContext2D(targetWidth, imageHeight);
|
const yResolution = extentHeight / imageHeight;
|
||||||
|
let targetWidth = imageWidth;
|
||||||
|
let targetHeight = imageHeight;
|
||||||
|
if (xResolution > yResolution) {
|
||||||
|
targetWidth = Math.round(extentWidth / yResolution);
|
||||||
|
} else {
|
||||||
|
targetHeight = Math.round(extentHeight / xResolution);
|
||||||
|
}
|
||||||
|
if (targetWidth !== imageWidth || targetHeight !== imageHeight) {
|
||||||
|
const context = createCanvasContext2D(targetWidth, targetHeight);
|
||||||
assign(context, this.getContextOptions());
|
assign(context, this.getContextOptions());
|
||||||
const canvas = context.canvas;
|
const canvas = context.canvas;
|
||||||
context.drawImage(
|
context.drawImage(
|
||||||
|
|||||||
Reference in New Issue
Block a user