完善绘制iamge的aspectFill模式
This commit is contained in:
parent
4a25807866
commit
12c6422b0e
24
lib/pen.js
24
lib/pen.js
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user