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 小时前
前端应用首屏加载速度优化全攻略
前端·状态模式
Mike_jia5 小时前
LiteOps:轻量级CI/CD平台,重塑开发运维新体验
前端
浮游本尊5 小时前
React 18.x 学习计划 - 第十四天:实战整合与进阶收尾
前端·学习·react.js
_Eleven10 小时前
Tailwind CSS vs UnoCSS 深度对比
前端
NEXT0610 小时前
TCP 与 UDP 核心差异及面试高分指南
前端·网络协议·面试
qq_242188633210 小时前
HTML 全屏烟花网页
前端·html
曲幽10 小时前
FastAPI实战:WebSocket长连接保持与心跳机制,从入门到填坑
javascript·python·websocket·keep-alive·fastapi·heartbeat·connection
码云数智-大飞10 小时前
前端性能优化全链路实战:从加载速度到渲染效率的极致提速方案
前端·性能优化
锅包一切10 小时前
【蓝桥杯JavaScript基础入门】一、JavaScript基础
开发语言·前端·javascript·蓝桥杯