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>

相关推荐
林恒smileZAZ5 小时前
Vue<前端页面版本检测>
前端·javascript·vue.js
码事漫谈8 小时前
当AI开始“思考”:我们是否真的准备好了?
前端·后端
许杰小刀8 小时前
ctfshow-web文件包含(web78-web86)
android·前端·android studio
我是Superman丶9 小时前
Element UI 表格某行突出悬浮效果
前端·javascript·vue.js
恋猫de小郭9 小时前
你的代理归我了:AI 大模型恶意中间人攻击,钱包都被转走了
前端·人工智能·ai编程
xiaokuangren_10 小时前
前端css颜色
前端·css
Huanzhi_Lin10 小时前
关于V8/MajorGC/MinorGC——性能优化
javascript·性能优化·ts·js·v8·新生代·老生代
hoiii18710 小时前
C# 基于 LumiSoft 实现 SIP 客户端方案
前端·c#
anOnion10 小时前
构建无障碍组件之Meter Pattern
前端·html·交互设计
小码哥_常11 小时前
Spring Boot配置diff:解锁配置管理新姿势
前端