原生小程序用画布制作海报,等比例缩放,和uniapp差不多就是写法有点不同

最后直接看效果图;不废话,直接上代码,效果图。

(四个文件复制直接可以使用,代码有注释)

思路:当以iphone6/7/8 基础的时候,你就会看到 获取屏幕的宽为350,高为603,这个是微信开发工具的获取的屏幕的数据。 1、 图片在canvas的时候,你可以先设置好高度,和宽度。 2、 当你的canvas需要放到其他的手机屏幕的时,你需要用其他手机的 宽/iphone678宽 高/iphone678高 获取的它(放大或缩小)的比例。3、然后再分别乘以图片的宽、高 4、文字也和图片一样需要设置宽高
js↓↓↓↓↓↓文件 :

// pages/manage/myshare/painter.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
var foo = 'bar';
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
// canvas.js
    onReady: function (e) {

	},  
    sening: function(e) {
	    var that = this;
			wx.getSystemInfo({
				success: function(res) {
					console.log(res.windowHeight)
					console.log(res.windowWidth)
					console.log(res.pixelRatio)
					let windowscale = res.windowHeight/res.windowWidth;
					console.log(windowscale)
					// 把数据放到data
					that.setData({
						windowHeight: res.windowHeight,
						windowWidth: res.windowWidth,
						windowscale:windowscale,
						psScal:res.windowWidth/350,//宽//以iphone6/7/8 宽高为基准。用其他也行,进行比例伸缩
						psScal1:res.windowHeight/603//高//以iphone6/7/8 宽高为基准。用其他也行,进行比例伸缩
					})
				},
			})
			var windowWidth = Number(that.data.windowWidth);
			var windowHeight = Number(that.data.windowHeight)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值