This commit is contained in:
CPPAlien 2018-12-03 16:24:08 +08:00
commit 539f395018

View File

@ -226,22 +226,20 @@ export default class Painter {
height, height,
} = this._preProcess(view); } = this._preProcess(view);
// 获得缩放到图片大小级别的裁减框 // 获得缩放到图片大小级别的裁减框
let rWidth; let rWidth = view.sWidth;
let rHeight; let rHeight = view.sHeight;
let startX = 0; let startX = 0;
let startY = 0; let startY = 0;
if (view.sHeight > view.sWidth) { // 绘画区域比例
rHeight = Math.round((view.sWidth / width) * height); const cp = width / height;
rWidth = view.sWidth; // 原图比例
} else { const op = view.sWidth / view.sHeight;
rWidth = Math.round((view.sHeight / height) * width); if (cp >= op) {
rHeight = view.sHeight; rHeight = rWidth / cp;
}
if (view.sWidth > rWidth) {
startX = Math.round((view.sWidth - rWidth) / 2);
}
if (view.sHeight > rHeight) {
startY = Math.round((view.sHeight - rHeight) / 2); startY = Math.round((view.sHeight - rHeight) / 2);
} else {
rWidth = rHeight * cp;
startX = Math.round((view.sWidth - rWidth) / 2);
} }
if (view.css && view.css.mode === 'scaleToFill') { if (view.css && view.css.mode === 'scaleToFill') {
this.ctx.drawImage(view.url, -(width / 2), -(height / 2), width, height); this.ctx.drawImage(view.url, -(width / 2), -(height / 2), width, height);