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>

相关推荐
雪芽蓝域zzs2 分钟前
uni-app原生editor封装编辑组件(vue3)
uni-app
ai_coder_ai2 分钟前
使用web ide开发和调试自动化脚本
前端·ide·自动化
wyc是xxs3 分钟前
用纯 Node.js 写了一个 JS 解释器 — kernel-js-lite
开发语言·javascript·npm·node.js
kaikaile19957 分钟前
盲源分离(BSS)程序代码:信号处理与模态识别
前端·信号处理
之歆11 分钟前
Day01_ES6+ 专业指南:从基础到实战的现代JavaScript开发(上)
javascript·mysql·es6
weixin_BYSJ198712 分钟前
基于Django的非物质文化遗产管理系统设计与实现(源码 + 文档)98950
java·javascript·spring boot·python·django·flask·php
এ慕ོ冬℘゜12 分钟前
从零封装企业级通用确认弹窗组件|高复用、低耦合、适配全场景
开发语言·前端·javascript
Bigger12 分钟前
现在面试官竟然这么问问题,你知道吗?😮
前端·人工智能·agent
祀爱30 分钟前
ControllerBase 类将对象转换为 JSON 格式并返回前端的方法
前端·json·asp.net