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,
} = this._preProcess(view);
// 获得缩放到图片大小级别的裁减框
let rWidth;
let rHeight;
let rWidth = view.sWidth;
let rHeight = view.sHeight;
let startX = 0;
let startY = 0;
if (view.sHeight > view.sWidth) {
rHeight = Math.round((view.sWidth / width) * height);
rWidth = view.sWidth;
} else {
rWidth = Math.round((view.sHeight / height) * width);
rHeight = view.sHeight;
}
if (view.sWidth > rWidth) {
startX = Math.round((view.sWidth - rWidth) / 2);
}
if (view.sHeight > rHeight) {
// 绘画区域比例
const cp = width / height;
// 原图比例
const op = view.sWidth / view.sHeight;
if (cp >= op) {
rHeight = rWidth / cp;
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') {
this.ctx.drawImage(view.url, -(width / 2), -(height / 2), width, height);