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>

相关推荐
程序员小寒几秒前
Vue.js 为什么要推出 Vapor Mode?
前端·javascript·vue.js
白菜__8 分钟前
去哪儿小程序逆向分析(酒店)
前端·javascript·爬虫·网络协议·小程序·node.js
前端老曹8 分钟前
Jspreadsheet CE V5 使用手册(保姆版) 二
开发语言·前端·vue.js·学习
IT_陈寒10 分钟前
SpringBoot3.0实战:5个高并发场景下的性能优化技巧,让你的应用快如闪电⚡
前端·人工智能·后端
秋邱10 分钟前
AR 定位技术深度解析:从 GPS 到视觉 SLAM 的轻量化实现
开发语言·前端·网络·人工智能·python·html·ar
云飞云共享云桌面17 分钟前
佛山某机械加工设备工厂10个SolidWorks共享一台服务器的软硬件
大数据·运维·服务器·前端·网络·人工智能·性能优化
开发者小天21 分钟前
React中使用classnames的案例
前端·react.js·前端框架
简单的话*28 分钟前
Logback 日志按月归档并保留 180 天,超期自动清理的配置实践
java·前端·python
困惑阿三31 分钟前
深入理解 JavaScript 中的(Promise.race)
开发语言·前端·javascript·ecmascript·reactjs
我命由我1234532 分钟前
微信小程序 bind:tap 与 bindtap 的区别
开发语言·前端·javascript·微信小程序·小程序·前端框架·js