fix: 解决首次绘制可能出现的canvas尺寸问题
This commit is contained in:
parent
c26ff78fe5
commit
4adce6a615
78
painter.js
78
painter.js
@ -662,49 +662,49 @@ Component({
|
|||||||
|
|
||||||
startPaint() {
|
startPaint() {
|
||||||
this.initScreenK();
|
this.initScreenK();
|
||||||
|
const {
|
||||||
|
width,
|
||||||
|
height
|
||||||
|
} = this.properties.palette;
|
||||||
|
|
||||||
this.downloadImages(this.properties.palette).then(async (palette) => {
|
if (!width || !height) {
|
||||||
const {
|
console.error(`You should set width and height correctly for painter, width: ${width}, height: ${height}`);
|
||||||
width,
|
return;
|
||||||
height
|
}
|
||||||
} = palette;
|
|
||||||
|
|
||||||
if (!width || !height) {
|
let needScale = false;
|
||||||
console.error(`You should set width and height correctly for painter, width: ${width}, height: ${height}`);
|
// 生成图片时,根据设置的像素值重新绘制
|
||||||
return;
|
if (width.toPx() !== this.canvasWidthInPx) {
|
||||||
}
|
this.canvasWidthInPx = width.toPx();
|
||||||
|
needScale = this.properties.use2D;
|
||||||
|
}
|
||||||
|
if (this.properties.widthPixels) {
|
||||||
|
setStringPrototype(this.screenK, this.properties.widthPixels / this.canvasWidthInPx)
|
||||||
|
this.canvasWidthInPx = this.properties.widthPixels
|
||||||
|
}
|
||||||
|
|
||||||
let needScale = false;
|
if (this.canvasHeightInPx !== height.toPx()) {
|
||||||
// 生成图片时,根据设置的像素值重新绘制
|
this.canvasHeightInPx = height.toPx();
|
||||||
if (width.toPx() !== this.canvasWidthInPx) {
|
needScale = needScale || this.properties.use2D;
|
||||||
this.canvasWidthInPx = width.toPx();
|
}
|
||||||
needScale = this.properties.use2D;
|
this.setData({
|
||||||
}
|
photoStyle: `width:${this.canvasWidthInPx}px;height:${this.canvasHeightInPx}px;`,
|
||||||
if (this.properties.widthPixels) {
|
}, function () {
|
||||||
setStringPrototype(this.screenK, this.properties.widthPixels / this.canvasWidthInPx)
|
this.downloadImages(this.properties.palette).then(async palette => {
|
||||||
this.canvasWidthInPx = this.properties.widthPixels
|
if (!this.photoContext) {
|
||||||
}
|
this.photoContext = await this.getCanvasContext(this.properties.use2D, 'photo');
|
||||||
|
}
|
||||||
if (this.canvasHeightInPx !== height.toPx()) {
|
if (needScale) {
|
||||||
this.canvasHeightInPx = height.toPx();
|
const scale = getApp().systemInfo.pixelRatio;
|
||||||
needScale = needScale || this.properties.use2D;
|
this.photoContext.width = this.canvasWidthInPx * scale;
|
||||||
}
|
this.photoContext.height = this.canvasHeightInPx * scale;
|
||||||
this.setData({
|
this.photoContext.scale(scale, scale);
|
||||||
photoStyle: `width:${this.canvasWidthInPx}px;height:${this.canvasHeightInPx}px;`,
|
}
|
||||||
|
new Pen(this.photoContext, palette).paint(() => {
|
||||||
|
this.saveImgToLocal();
|
||||||
|
});
|
||||||
|
setStringPrototype(this.screenK, this.properties.scaleRatio);
|
||||||
});
|
});
|
||||||
if (!this.photoContext) {
|
|
||||||
this.photoContext = await this.getCanvasContext(this.properties.use2D, 'photo');
|
|
||||||
}
|
|
||||||
if (needScale) {
|
|
||||||
const scale = getApp().systemInfo.pixelRatio;
|
|
||||||
this.photoContext.width = this.canvasWidthInPx * scale;
|
|
||||||
this.photoContext.height = this.canvasHeightInPx * scale;
|
|
||||||
this.photoContext.scale(scale, scale);
|
|
||||||
}
|
|
||||||
new Pen(this.photoContext, palette).paint(() => {
|
|
||||||
this.saveImgToLocal();
|
|
||||||
});
|
|
||||||
setStringPrototype(this.screenK, this.properties.scaleRatio);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user