Показать сообщение отдельно
  #5 (permalink)  
Старый 13.05.2019, 15:31
Аватар для Alexandroppolus
Профессор
Отправить личное сообщение для Alexandroppolus Посмотреть профиль Найти все сообщения от Alexandroppolus
 
Регистрация: 25.10.2016
Сообщений: 1,005

навскидку, без clip

let MAX_WIDTH = 600;
let MAX_HEIGHT = 400;
let width = img.width;
let height = img.height;
let ratio = 1;

if (width > MAX_WIDTH || height > MAX_HEIGHT) {
    ratio = Math.max(width / MAX_WIDTH, height / MAX_HEIGHT);
    width = width / ratio;
    height = height / ratio;
}

......

//рендерим новое изображение с позициями и указанным форматом
ctx.drawImage(img, posX * ratio, posY * ratio, this.state.w * ratio, this.state.h * ratio, 
        posX, posY, this.state.w, this.state.h);
Ответить с цитированием