自己开发了一个插值算法,可以复制图像。
function Copy(img, w, h) {
w = Math.round(w)
h = Math.round(h)
let dx = img.width / w,
dy = img.height / h;
let tmp = Array.from({length:h*w*4}, (_, i)=>{
let x = Math.floor((i % w)),
y = Math.floor((i - x) / w),
b = i % 4;
console.log(x, y)
x = Math.round(x * dx)
y = Math.round(y * dy)
return img.data[(y * img.width + x) * 4 + b]
})
return new ImageData(new Uint8ClampedArray(tmp), w, h)
}