Reuse existing image element on conversion.

This commit is contained in:
GoteGuru 2022-05-20 01:15:03 +02:00
parent 16f6557e69
commit d01e2faa75

View file

@ -1006,10 +1006,14 @@ function editHeightmap() {
this.value = ""; // reset input value to get triggered if the file is re-uploaded this.value = ""; // reset input value to get triggered if the file is re-uploaded
const reader = new FileReader(); const reader = new FileReader();
const img = new Image(); const imgId = "imageToConvert";
img.id = "imageToConvert"; let img = document.getElementById(imgId);
img.style.display = "none"; if (!img) {
document.body.appendChild(img); img = new Image();
img.id = imgId;
img.style.display = "none";
document.body.appendChild(img);
}
img.onload = function () { img.onload = function () {
const ctx = document.getElementById("canvas").getContext("2d"); const ctx = document.getElementById("canvas").getContext("2d");