Merge pull request #12393 from mike-000/patch-6
Scale up static Image and round to nearest pixel to avoid rounding errors
This commit is contained in:
@@ -136,6 +136,7 @@ class ImageWrapper extends ImageBase {
|
||||
*/
|
||||
setImage(image) {
|
||||
this.image_ = image;
|
||||
this.resolution = getHeight(this.extent) / this.image_.height;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -135,10 +135,19 @@ class Static extends ImageSource {
|
||||
imageWidth = image.width;
|
||||
imageHeight = image.height;
|
||||
}
|
||||
const resolution = getHeight(imageExtent) / imageHeight;
|
||||
const targetWidth = Math.ceil(getWidth(imageExtent) / resolution);
|
||||
if (targetWidth != imageWidth) {
|
||||
const context = createCanvasContext2D(targetWidth, imageHeight);
|
||||
const extentWidth = getWidth(imageExtent);
|
||||
const extentHeight = getHeight(imageExtent);
|
||||
const xResolution = extentWidth / imageWidth;
|
||||
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());
|
||||
const canvas = context.canvas;
|
||||
context.drawImage(
|
||||
|
||||
Reference in New Issue
Block a user