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>

相关推荐
长安牧笛4 分钟前
社区银发智慧陪伴系统,AI模拟家人语气聊天,监测老年人日常活动,如用药,出门,异常情况,自动推送给子女,兼顾陪伴与安全。
javascript
HIT_Weston4 分钟前
65、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(九)
前端·ubuntu·gitlab
阿蒙Amon4 分钟前
JavaScript学习笔记:3.控制流与错误处理
javascript·笔记·学习
b***74886 分钟前
前端的未来不是框架之争,而是数字体验能力的全面竞争
前端
Lunar*12 分钟前
[开源] 纯前端实现楼盘采光模拟工具:从2D规划图到3D日照分析
前端·3d
前端不太难15 分钟前
RN 遇到复杂手势(缩放、拖拽、旋转)时怎么设计架构
javascript·vue.js·架构
白兰地空瓶15 分钟前
一行 npm init vite,前端工程化的世界就此展开
前端·vue.js·vite
LYFlied15 分钟前
【每日算法】LeetCode 23. 合并 K 个升序链表
前端·数据结构·算法·leetcode·链表
xiaoxue..16 分钟前
LeetCode 第 15 题:三数之和
前端·javascript·算法·leetcode·面试
flashlight_hi19 分钟前
LeetCode 分类刷题:101. 对称二叉树
javascript·算法·leetcode