uni.chooseImage...
uni.getimageInfo({
src: res.tempFilePaths[0],
success: (res) => {
const blobUrl = res.path;
const canvas = document.createElement("canvas");
// 减少绘制的大小才能压缩,不然可能压缩后图片会变大
canvas.width = res.width / 2;
canvas.height = res.height / 2;
const ctx = canvas.getContext("2d");
let img = new Image();
img.src = blobUrl;
img.error = uni.hideLoading;
img.onload = () => {
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
const contentType = "image/png";
canvas.toBlob(
async (blob) => {
const blobUrl2 = window.URL.createObjectURL(blob);
await _upload(blobUrl2); // 使用uniapp的文件上传api发送FormData数据
window.URL.revokeObjectURL(blobUrl2);
img = null;
},
contentType,
0.5
);
};
},
fail: uni.hideLoading,
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。