uniapp 将图片转成JPG格式

<template>

<view style="width: 100%; height: 100%;">

<image :src="imagePath" lazy-load style="width: 100%; height: 100%;"></image>

<canvas

style="background-color: red;"

:style="{width: target.width + 'px', height: target.height + 'px'}" canvas-id="target"></canvas>

</view>

</template>

<script>

export default {

data() {

return {

targetContext: null,

imagePath: '',

target: {

width: 300,

height: 300

}

}

},

onLoad(e) {

console.log(e);

// this.imagePath = e.imagepath;

this.targetContext = uni.createCanvasContext("target", this); //第一个画布

this.imageDetailMsg(e.imagepath);

},

methods: {

imageDetailMsg(imageUrl) {

let self = this;

uni.getImageInfo({

src: imageUrl,

success: function(imageInfo) {

console.log(imageInfo);

setTimeout(() => {

self.targetContext.drawImage(imageInfo.path, 0, 0, 300, 300, 0, 0, 300, 300);

self.targetContext.draw(false, () => {

uni.canvasToTempFilePath({

canvasId: "target",

fileType:'jpg',

success: (res) => {

var path = res.tempFilePath;

console.log('裁剪后的图片',res);

self.imagePath = path;

},

fail: (ev) => {

console.log(ev);

},

complete: () => {

}

}, self);

});

}, 100);

}

})

},

}

}

</script>

<style>

</style>

相关推荐
Justin3go3 小时前
HUNT0 上线了——尽早发布,尽早发现
前端·后端·程序员
怕浪猫4 小时前
第一章 JSX 增强特性与函数组件入门
前端·javascript·react.js
铅笔侠_小龙虾4 小时前
Emmet 常用用法指南
前端·vue
钦拆大仁4 小时前
跨站脚本攻击XSS
前端·xss
前端小L5 小时前
贪心算法专题(十):维度权衡的艺术——「根据身高重建队列」
javascript·算法·贪心算法
VX:Fegn08956 小时前
计算机毕业设计|基于springboot + vue校园社团管理系统(源码+数据库+文档)
前端·数据库·vue.js·spring boot·后端·课程设计
Fortunate Chen6 小时前
类与对象(下)
java·javascript·jvm
ChangYan.6 小时前
直接下载源码但是执行npm run compile后报错
前端·npm·node.js
skywalk81637 小时前
在 FreeBSD 上可以使用的虚拟主机(Web‑Hosting)面板
前端·主机·webmin