Improve pixel reading performance a bit

This commit is contained in:
Lukas Rieger (Blue) 2022-10-16 00:35:06 +02:00
parent 7e9f0e0bd8
commit 5be6dc8089
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
1 changed files with 3 additions and 1 deletions

View File

@ -384,7 +384,9 @@ export const vecArrToObj = (val, useZ = false) => {
const pixel = document.createElement('canvas');
pixel.width = 1;
pixel.height = 1;
const pixelContext = pixel.getContext('2d');
const pixelContext = pixel.getContext('2d', {
willReadFrequently: true
});
export const getPixel = (img, x, y) => {
pixelContext.drawImage(img, Math.floor(x), Math.floor(y), 1, 1, 0, 0, 1, 1);