fix:用canvas裁剪缩放1080×1080替代plus.zip(不兼容nvue)
This commit is contained in:
parent
0a572aae0f
commit
a83e43af39
@ -66,6 +66,9 @@
|
||||
</view>
|
||||
<image class="cc-preview-img" :src="previewSrc" mode="aspectFill" :style="'width:' + previewSize + 'px;height:' + previewSize + 'px;'"></image>
|
||||
</view>
|
||||
|
||||
<!-- 隐藏的canvas(用于裁剪缩放) -->
|
||||
<canvas canvas-id="resizeCanvas" style="width:1080px;height:1080px;position:fixed;left:-9999px;top:-9999px;"></canvas>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -141,27 +144,28 @@
|
||||
var w = info.width
|
||||
var h = info.height
|
||||
var size = Math.min(w, h)
|
||||
var clipX = Math.floor((w - size) / 2)
|
||||
var clipY = Math.floor((h - size) / 2)
|
||||
plus.zip.compressImage({
|
||||
src: srcPath,
|
||||
dst: '_doc/sq_' + Date.now() + '.jpg',
|
||||
width: '1080',
|
||||
height: '1080',
|
||||
quality: 95,
|
||||
overwrite: true,
|
||||
clip: {
|
||||
x: clipX,
|
||||
y: clipY,
|
||||
width: size,
|
||||
height: size
|
||||
}
|
||||
var sx = Math.floor((w - size) / 2)
|
||||
var sy = Math.floor((h - size) / 2)
|
||||
// 用canvas裁剪 + 缩放
|
||||
var ctx = uni.createCanvasContext('resizeCanvas', that)
|
||||
ctx.drawImage(srcPath, sx, sy, size, size, 0, 0, 1080, 1080)
|
||||
ctx.draw(false, function() {
|
||||
setTimeout(function() {
|
||||
uni.canvasToTempFilePath({
|
||||
canvasId: 'resizeCanvas',
|
||||
x: 0, y: 0,
|
||||
width: 1080, height: 1080,
|
||||
destWidth: 1080, destHeight: 1080,
|
||||
fileType: 'jpg',
|
||||
quality: 1,
|
||||
success: function(res) {
|
||||
that.capturedList.push(res.tempFilePath)
|
||||
},
|
||||
function(res) {
|
||||
that.capturedList.push(res.target)
|
||||
},
|
||||
function() {
|
||||
fail: function() {
|
||||
that.capturedList.push(srcPath)
|
||||
}
|
||||
}, that)
|
||||
}, 300)
|
||||
})
|
||||
},
|
||||
fail: function() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user