最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序?qū)崿F(xiàn)拍照畫布指定區(qū)域生成圖片

 更新時(shí)間:2019年07月18日 09:20:30   作者:xiangxx@酷  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)拍照畫布指定區(qū)域生成圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

最近寫識(shí)別行駛證功能,點(diǎn)擊拍照把指定區(qū)域截取,生成圖片功能。

系統(tǒng)相機(jī)。該組件是原生組件,使用時(shí)請(qǐng)注意相關(guān)限制。 掃碼二維碼功能,需升級(jí)微信客戶端至6.7.3。

微信小程序Camera相機(jī)地址

我們看下效果:

1、首先生成一個(gè)CanvasContext:

/**
 * 生命周期函數(shù)--監(jiān)聽頁面加載
 */
 onLoad: function(options) {
 requireJs.adaptionIphoneX(this);
 
 this.ctx = wx.createCameraContext()
 
 },

2、相機(jī)的 wxml樣式

<camera wx:if='{{isShowCamera}}' device - position="width" flash="off" style="width:{{windowWidth}}px; height:{{windowHeight}}px;">
 
 <cover-view class='camerabgImage-view'>
  <cover-image class='bgImage' src='{{isIphoneX==true?"../../myImage/vehicle/biankuang_x.png":"../../myImage/vehicle/biankuang.png"}}'> </cover-image>
 
  <cover-view class='cameratop-view1'>中華人民共和國(guó)機(jī)動(dòng)車行駛證</cover-view>
  <cover-view class='cameratop-view2'>(行駛證主頁)</cover-view>
  <cover-view class='cameracenter-view' style='top:{{isIphoneX==true?"52%":"62%"}}'>請(qǐng)對(duì)準(zhǔn)左下角發(fā)證機(jī)關(guān)印章</cover-view>
 
  <!-- 拍照按鈕 --> 
  <cover-view class='camerabotton-view' style='bottom:{{isIphoneX==true?"75px":"0px"}}'>
  <cover-image class='cancelphoto' src='../../myImage/vehicle/quxiao.png' bindtap='cancelPhotoAction'></cover-image>
  <cover-image class='takephoto' src='../../myImage/vehicle/paizhao.png' bindtap='takePhotoAction'></cover-image>
  
  <cover-view class='skipphoto' bindtap='skipphotoAction'>{{skipphotoStatus==1?"跳過":""}}
  </cover-view>
  
  </cover-view>
 
 </cover-view>
 
 </camera>
 
 <canvas wx:if='{{isShowImage}}' canvas-id="image-canvas" style='width:{{windowWidth}}px; height:{{windowHeight}}px;'></canvas>

3、相機(jī)的 wxss樣式

.camerabgImage-view{
 height: 100%;
 width: 100%;
 position:absolute;
}
.bgImage{
 width: 100%;
 height: 100%;
 position: absolute;
}
 
.cameratop-view1{
 margin-top: 174rpx;
}
.cameratop-view2{
 margin-top: 220rpx;
}
.cameratop-view1, .cameratop-view2{
 width: 100%;
 display: flex;
 justify-content: center;
 position: absolute;
 
 font-family: PingFangSC-Medium;
 font-size: 36rpx;
 color: #FFFFFF;
 letter-spacing: 0;
 text-align: center;
}
 
.cameracenter-view{
 height: 44rpx;
 width: 100%;
 position: absolute;
 
 font-family: PingFangSC-Medium;
 font-size: 32rpx;
 color: #FFFFFF;
 letter-spacing: 0;
 text-align: center;
}
 
/* 底部 */
.camerabotton-view{
 height: 200rpx;
 width: 100%;
 position:absolute;
 
 display: flex;
 justify-content: space-around;
 align-items: center;
}
.cancelphoto{
 width: 50rpx;
 height: 50rpx;
}
.takephoto{
 width: 132rpx;
 height: 132rpx;
}
.skipphoto{
 font-family: PingFangSC-Regular;
 font-size: 32rpx;
 color: #FFFFFF;
 letter-spacing: 0;
 text-align: center;
}

4、js 中訪問原生組件 camera  主要針對(duì)相機(jī)權(quán)限處理

微信小程序權(quán)限地址

onShow: function() {
 var that = this
 wx.authorize({
  scope: 'scope.camera',
  success: function (res) {
  that.setData({
   isShowCamera: true,
  })
  },
  fail: function (res) {
  console.log("" + res);
  wx.showModal({
   title: '請(qǐng)求授權(quán)您的攝像頭',
   content: '如需正常使用此小程序功能,請(qǐng)您按確定并在設(shè)置頁面授權(quán)用戶信息',
   confirmText: '確定',
   success: res => {
   if (res.confirm) {
    wx.openSetting({
    success: function (res) {
     console.log('成功');
     console.log(res);
     if (res.authSetting['scope.camera']) { //設(shè)置允許獲取攝像頭
     console.log('設(shè)置允許獲取攝像頭')
     wx.showToast({
      title: '授權(quán)成功',
      icon: 'success',
      duration: 1000
     })
     that.setData({
      isShowCamera: true,
     })
 
     } else { //不允許
     wx.showToast({
      title: '授權(quán)失敗',
      icon: 'none',
      duration: 1000
     })
     wx.redirectTo({
      url: 'addCarInfo/addCarInfo',
     })
     }
    }
    })
   } else { //取消
    wx.showToast({
    title: '授權(quán)失敗',
    icon: 'none',
    duration: 1000
    })
    wx.redirectTo({
    url: 'addCarInfo/addCarInfo',
    })
   }
   }
  })
 
  }
 })
 },

5、頁面初始化數(shù)據(jù)

/**
 * 頁面的初始數(shù)據(jù)
 */
 data: {
 isShowCamera: false,
 width: 10,
 height: 10,
 src: "",
 image: "",
 skipphotoStatus: "0",// 1跳過 0沒有跳過
 isShowImage: false
 },

 6、點(diǎn)擊拍照 設(shè)置照片, 返回拍照?qǐng)D片

/**
 * 拍照
 */
 takePhotoAction: function() {
 var that = this
 that.ctx.takePhoto({
  quality: 'high', //高質(zhì)量
  success: (res) => {
  this.loadTempImagePath(res.tempImagePath);
  },
 })
 },

 7、針對(duì)原圖片截取尺寸 與 截取后的圖片

 loadTempImagePath: function(options) {
 var that = this
 that.path = options
 wx.getSystemInfo({
  success: function(res) {
 
  // 矩形的位置
  var image_x = 15;
  var image_y = 150;
  var image_width = that.data.width - 2 * 15;
  var image_height = 238;
 
  wx.getImageInfo({
   src: that.path,
   success: function(res) {
   that.setData({
    isShowImage: true,
   })
   that.canvas = wx.createCanvasContext("image-canvas", that)
   //過渡頁面中,圖片的路徑坐標(biāo)和大小
   that.canvas.drawImage(that.path, 0, 0, that.data.width, that.data.height)
   wx.showLoading({
    title: '數(shù)據(jù)處理中...',
    icon: 'loading',
    duration: 10000
   })
   // 這里有一些很神奇的操作,總結(jié)就是MD拍出來的照片規(guī)格居然不是統(tǒng)一的過渡頁面中,對(duì)裁剪框的設(shè)定
   that.canvas.setStrokeStyle('black')
   that.canvas.strokeRect(image_x, image_y, image_width, image_height)
   that.canvas.draw()
   setTimeout(function() {
    wx.canvasToTempFilePath({ //裁剪對(duì)參數(shù)
    canvasId: "image-canvas",
    x: image_x, //畫布x軸起點(diǎn)
    y: image_y, //畫布y軸起點(diǎn)
    width: image_width, //畫布寬度
    height: image_height, //畫布高度
    destWidth: image_width, //輸出圖片寬度
    destHeight: image_height, //輸出圖片高度
    success: function(res) {
     that.setData({
     image: res.tempFilePath,
     })
     //清除畫布上在該矩形區(qū)域內(nèi)的內(nèi)容。
     // that.canvas.clearRect(0, 0, that.data.width, that.data.height)
     // that.canvas.drawImage(res.tempFilePath, image_x, image_y, image_width, image_height)
     // that.canvas.draw()
     wx.hideLoading()
 
     console.log(res.tempFilePath);
     //在此可進(jìn)行網(wǎng)絡(luò)請(qǐng)求
     PublicJS.drivinglicenseUpload(res.tempFilePath, that.uploadFile);
    },
    fail: function(e) {
     wx.hideLoading()
     wx.showToast({
     title: '出錯(cuò)啦...',
     icon: 'loading'
     })
     if (this.data.skipphotoStatus == 1) {
     wx.redirectTo({
      url: 'addCarInfo/addCarInfo',
     })
     } else {
     wx.navigateBack({
      delta: 1
     });
     }
    }
    });
   }, 1000);
   }
  })
  }
 })
 },
 
// 接口返回結(jié)果
 
uploadFile: function(data) {}

 微信小程序Canvas畫布地址

1.canvas組件是由客戶端創(chuàng)建的原生組件,它的層級(jí)是最高的。

2.請(qǐng)勿在scroll-view中使用canvas組件。

3.css動(dòng)畫對(duì)canvas組件無效。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • js正則表達(dá)式常用方法梳理(附代碼案例)

    js正則表達(dá)式常用方法梳理(附代碼案例)

    正則表達(dá)式在我們?nèi)粘痰墓ぷ黜?xiàng)目中,應(yīng)該是一個(gè)經(jīng)常用到的技能,在做一些字符的匹配和處理的過程中,發(fā)揮了很大的作用,這篇文章主要給大家介紹了關(guān)于js正則表達(dá)式常用方法的相關(guān)資料,需要的朋友可以參考下
    2024-05-05
  • 對(duì)TypeScript庫進(jìn)行單元測(cè)試的方法

    對(duì)TypeScript庫進(jìn)行單元測(cè)試的方法

    這篇文章主要介紹了對(duì)TypeScript庫進(jìn)行單元測(cè)試的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • 微信小程序自定義組件之可清除的input組件

    微信小程序自定義組件之可清除的input組件

    最近正在做的一個(gè)小程序項(xiàng)目中需要用到一個(gè)可清除的輸入框控件,為了方便小編直接使用了可清除的input自定義組件,下面腳本之家小編給大家?guī)砹宋⑿判〕绦蜃远x組件之可清除的input組件,感興趣的朋友一起看看吧
    2018-07-07
  • 如何通過IntersectionObserver實(shí)現(xiàn)懶加載

    如何通過IntersectionObserver實(shí)現(xiàn)懶加載

    這篇文章主要介紹了通過IntersectionObserver實(shí)現(xiàn)懶加載,本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-04-04
  • javascript實(shí)現(xiàn)信息增刪改查的方法

    javascript實(shí)現(xiàn)信息增刪改查的方法

    這篇文章主要介紹了javascript實(shí)現(xiàn)信息增刪改查的方法,實(shí)例分析了javascript操作頁面元素實(shí)現(xiàn)針對(duì)頁面信息的增刪改查功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • 基于JavaScript實(shí)現(xiàn)幸運(yùn)抽獎(jiǎng)頁面

    基于JavaScript實(shí)現(xiàn)幸運(yùn)抽獎(jiǎng)頁面

    這篇文章主要為大家詳細(xì)介紹了基于JavaScript實(shí)現(xiàn)幸運(yùn)抽獎(jiǎng)頁面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Bootstrap樹形組件jqTree的簡(jiǎn)單封裝

    Bootstrap樹形組件jqTree的簡(jiǎn)單封裝

    這篇文章主要介紹了Bootstrap樹形組件jqTree的簡(jiǎn)單封裝,封裝一個(gè)稍微完整點(diǎn)的樹形組件,感興趣的小伙伴們可以參考一下
    2016-01-01
  • JavaScript引用類型Array實(shí)例分析

    JavaScript引用類型Array實(shí)例分析

    這篇文章主要介紹了JavaScript引用類型Array,結(jié)合實(shí)例形式較為詳細(xì)的分析了JavaScript數(shù)組相關(guān)的創(chuàng)建、檢測(cè)、轉(zhuǎn)換、排序、棧、隊(duì)列、引用等各種常見操作技巧,需要的朋友可以參考下
    2018-07-07
  • Js中安全獲取Object深層對(duì)象的方法實(shí)例

    Js中安全獲取Object深層對(duì)象的方法實(shí)例

    Object是JavaScript基本數(shù)據(jù)類型之一(function也屬于object,是特殊的object),其存儲(chǔ)于堆中,這篇文章主要給大家介紹了關(guān)于Js中安全獲取Object深層對(duì)象的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • 微信小程序?qū)崿F(xiàn)數(shù)字滾動(dòng)動(dòng)畫

    微信小程序?qū)崿F(xiàn)數(shù)字滾動(dòng)動(dòng)畫

    這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)數(shù)字滾動(dòng)動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07

最新評(píng)論

邯郸县| 南木林县| 连城县| 新干县| 平安县| 霍林郭勒市| 宁蒗| 昌江| 东乌珠穆沁旗| 莎车县| 新和县| 秦安县| 正镶白旗| 牙克石市| 东乌珠穆沁旗| 永康市| 怀安县| 临夏市| 双辽市| 静海县| 德钦县| 竹山县| 闻喜县| 绥阳县| 县级市| 京山县| 临海市| 小金县| 台东市| 镇坪县| 新巴尔虎右旗| 定远县| 丹巴县| 彰武县| 乌鲁木齐市| 祥云县| 青铜峡市| 广饶县| 淅川县| 教育| 怀柔区|