图片上传功能

chooseImage(e) {
wx.chooseImage({
sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
success: res => {
const images = this.data.images.concat(res.tempFilePaths)
// 限制最多只能留下3张照片
this.data.images = images.length <= 3 ? images : images.slice(0, 3)
this.setData(this.data)
console.log(this.data)
}
})
}, removeImage(e) {
const idx = e.target.dataset.idx
this.data.images.splice(idx, 1)
this.setData(this.data)
}, handleImagePreview(e) {
const idx = e.target.dataset.idx
const images = this.data.images
wx.previewImage({
current: images[idx], //当前预览的图片
urls: images, //所有要预览的图片
})
}, submitForm(e) {
const title = this.data.title
const content = this.data.content
const imagess = this.data.images
var that = this
console.log(imagess);
wx.uploadFile({
url: 'http://127.0.0.1/upload.php',
filePath: imagess[0],
name: 'qimg',
timeout: 10000,
success: function(res){
if(res.statusCode == 200){
console.log(title)
console.log(content)
wx.request({
url: 'http://127.0.0.1/tijiao.php',
method: 'post',
data: {
x: res.data,
y: title,
z: content
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
success(res) {
console.log(res)
}
})
}
}
})
},

签名功能:

<view class="container">
<canvas canvas-id="firstCanvas" id='firstCanvas' bindtouchstart="bindtouchstart" bindtouchmove="bindtouchmove"></canvas>
<view class="btn"> <button type="warn" bindtap='clear'>
清除
</button>
<button type="primary" bindtap='export'>
提交
</button>
</view>
</view>
const app = getApp()

Page({
data: {
context: null,
index: 0,
height: 0,
width: 0
},
/**记录开始点 */
bindtouchstart: function (e) {
this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y)
},
/**记录移动点,刷新绘制 */
bindtouchmove: function (e) { this.data.context.lineTo(e.changedTouches[0].x, e.changedTouches[0].y);
this.data.context.stroke();
this.data.context.draw(true);
this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y);
}, /**清空画布 */
clear: function () {
this.data.context.clearRect(0, 0, this.data.width, this.data.height);
this.data.context.draw();
this.data.context.setStrokeStyle('#00ff00')
this.data.context.setLineWidth(2)
this.data.context.setFontSize(20)
let str = "签名区域";
this.data.context.fillText(str, Math.ceil((this.data.width - this.data.context.measureText(str).width) / 2), Math.ceil(this.data.height / 2) - 20)
this.data.context.draw()
},
/**导出图片 */
export: function () {
const that = this;
this.data.context.draw(false, wx.canvasToTempFilePath({
x: 0,
y: 0,
width: that.data.width,
height: that.data.height,
destWidth: that.data.width,
destHeight: that.data.height,
fileType: 'jpg',
canvasId: 'firstCanvas',
success(res) {
wx.uploadFile({
url: 'http://127.0.0.1/upload.php',
filePath: res.tempFilePath,
name: 'qimg',
success(res) {
console.log(res)
},
fail(err) {
wx.showToast({
title: '上传失败',
icon: 'none',
duration: 2000
})
}
}) },
fail() {
wx.showToast({
title: '导出失败',
icon: 'none',
duration: 2000
})
}
})) },
onLoad: function (options) {
console.log(options.id);
if (options.id) {
wx.showToast({
title: '姓名' + options.id,
icon: 'success',
duration: 2000
})
}
},
onShow: function () {
let query = wx.createSelectorQuery();
const that = this;
query.select('#firstCanvas').boundingClientRect();
query.exec(function (rect) {
let width = rect[0].width;
let height = rect[0].height;
that.setData({
width,
height
});
const context = wx.createCanvasContext('firstCanvas')
that.setData({
context: context
})
context.setStrokeStyle('#00ff00')
context.setLineWidth(2)
context.setFontSize(20)
let str = "";
context.fillText(str, Math.ceil((width - context.measureText(str).width) / 2), Math.ceil(height / 2) - 20)
context.draw()
});
}
})

微信小程序图片和签名的更多相关文章

  1. 微信小程序--图片相关问题合辑

    图片上传相关文章 微信小程序多张图片上传功能 微信小程序开发(二)图片上传 微信小程序上传一或多张图片 微信小程序实现选择图片九宫格带预览 ETL:微信小程序之图片上传 微信小程序wx.preview ...

  2. 微信小程序图片放大预览

    需求:当点击图片时,当前图片放大预览,且可以左右滑动 实现方式:使用微信小程序图片预览接口 我们可以看到api需要两个参数,分别通过下面的data-list和data-src来传到js中 wxml代码 ...

  3. 微信小程序 图片裁剪

    微信小程序 图片裁剪 分享一个微信小程序图片裁剪插件,很好用,支持旋转 文档:https://github.com/wyh19931106/image-cropper 1.json文件中添加image ...

  4. 微信小程序图片保存到本地

    微信小程序图片保存到本地是一个常用功能: 这里讲解下完整实现思路: 因为微信官方的授权只弹一次,用户拒绝后再次调用,就需要结合button组件的微信开放能力来调起,以下方案在微信各种授权中可参考. w ...

  5. 微信小程序图片上传和裁剪

    本篇博客用于解决微信小程序图片裁剪问题 图片裁剪常用于头像选择和图片合成等. 图片裁剪解决方案: 目前网络上知名的微信小程序图片裁剪插件是we-cropper(文末有链接) 操作步骤:下载好we-cr ...

  6. 关于微信小程序图片失真的解决方案

    今天来说一说 关于微信小程序的图片失真问题的解决,微信小程序的image标签要设置其宽高,不然图片若宽高过大会撑开原始图片大小的区域:如下 但是宽高设置固定了会导致有些图片和规定显示图片大小的比例不一 ...

  7. 5行代码实现微信小程序图片上传与腾讯免费5G存储空间的使用

    本文介绍了如何在微信小程序开发中使用腾讯官方提供的云开发功能快速实现图片的上传与存储,以及介绍云开发的 5G 存储空间的基本使用方法,这将大大提高微信小程序的开发效率,同时也是微信小程序系列教程的视频 ...

  8. 快速高效实现微信小程序图片上传与腾讯免费5G存储空间的使用

    本文介绍了如何在微信小程序开发中使用腾讯官方提供的云开发功能快速实现图片的上传与存储,以及介绍云开发的 5G 存储空间的基本使用方法,这将大大提高微信小程序的开发效率 对于一般的图片上传功能开发,我们 ...

  9. 微信小程序图片上传并展示

    1.首先编写微信小程序的页面和样式: index.js var total = []; Page({ data: { perImgSrc: [] }, onLoad: function (option ...

  10. 微信小程序---图片上传+服务端接受

    原文地址:http://blog.csdn.net/sk719887916/article/details/54312573 微信小程序,图片上传,应用地方-修改用户信息的头像. 详细代码: 小程序的 ...

随机推荐

  1. Grafana 系列文章(十三):如何用 Loki 收集查看 Kubernetes Events

    前情提要 IoT 边缘集群基于 Kubernetes Events 的告警通知实现 IoT 边缘集群基于 Kubernetes Events 的告警通知实现(二):进一步配置 概述 在分析 K8S 集 ...

  2. Codeforces Round #849 (Div. 4)

    A. Codeforces Checking 题意 每个案例给一个字符,如果在 "codeforces" 中出现过,输出 YES,否则输出 NO code /** * @autho ...

  3. Centos7下areaDetector IOC的编译后记

    https://github.com/EPICS-synApps/support/releases synApps出新版了,本文发文时的最新版为:R6-2 Centos7下areaDetector I ...

  4. 郁金香 注入DLL代码 与MFC窗口DLL文件 开源

    10/10号更新 DLL注入器注入DLL卡死 问题 新增打开控制台 将阳光输出到控制台中 注入DLL代码 1 #include <stdio.h> 2 #include<Window ...

  5. 加密,各种加密,耙梳加密算法(Encryption)种类以及开发场景中的运用(Python3.10)

    不用说火爆一时,全网热议的Web3.0区块链技术,也不必说诸如微信支付.支付宝支付等人们几乎每天都要使用的线上支付业务,单是一个简简单单的注册/登录功能,也和加密技术脱不了干系,本次我们耙梳各种经典的 ...

  6. .NET 8 预览版 1:NativeAOT 升级和新的Blazor United

    .NET团队 今天在官方博客上 发布了.NET 8的第一个预览版,.NET 8 是一个长期支持 (LTS) 版本[1],.NET 的版本包括产品.库.运行时和工具,是 Microsoft 内部和外部多 ...

  7. Spring Boot学习笔记(一)----概要与入门

    本文来自博客园,作者:{张果},转载请注明原文链接:{SpringBoot学习笔记(一)--SpringBoot概要与快速入门} 一.Spring Boot概要 没有Spring Boot开发项目时各 ...

  8. SQL语句中 left join 后用 on 还是 where,区别大了!

    前天写SQL时本想通过 A left B join on and 后面的条件来使查出的两条记录变成一条,奈何发现还是有两条. 后来发现 join on and 不会过滤结果记录条数,只会根据and后的 ...

  9. nodemon 实现 TypeScript 项目热部署

    下载安装 ts-node.nodemon: npm i -D ts-node nodemon 配置package.json脚本: "dev": "nodemon --wa ...

  10. ASP和jq实现url传递参数乱码的escape编码和unescape解码

    <% Function vbsEscape(str)    dim i,s,c,a    s=""    For i=1 to Len(str)        c=Mid(s ...