当前位置: 首页 > news >正文

网站外链快速建设免费平台推广

网站外链快速建设,免费平台推广,电商平台的营销策略,asp.net 网站开发框架自定义相机起因由于最近用uniapp调用原生相机容易出现闪退问题,找了很多教程又是压缩图片又是优化代码,我表示并没有太大作用!!实现自定义相机使用效果图拓展实现多种自定义相机水印相机身份证相机人像相机起因 由于最近用uniapp调用原生相机容易出现闪退…

自定义相机

  • 起因
    • 由于最近用uniapp调用原生相机容易出现闪退问题,找了很多教程又是压缩图片又是优化代码,我表示并没有太大作用!!
  • 实现自定义相机
    • 使用
      • 效果图
  • 拓展
  • 实现多种自定义相机
    • 水印相机
    • 身份证相机
    • 人像相机

起因

由于最近用uniapp调用原生相机容易出现闪退问题,找了很多教程又是压缩图片又是优化代码,我表示并没有太大作用!!

于是开启了我的解决之路

  • 利用livePusher实现

实现自定义相机

拓展性挺强的,可以实现自定义水印、身份证拍摄、人像拍摄等
这里我简单实现一个相机功能主要用于解决闪退

Tip:这里需要创建nvue文件哦~

创建camera.nvue

<template><view class="pengke-camera" :style="{ width: windowWidth, height: windowHeight }"><live-pusherid="livePusher"ref="livePusher"class="livePusher"mode="FHD"beauty="0"whiteness="0":aspect="aspect"min-bitrate="1000"audio-quality="16KHz"device-position="back":auto-focus="true":muted="true":enable-camera="true":enable-mic="false":zoom="false"@statechange="statechange":style="{ width: windowWidth, height: windowHeight }"></live-pusher><view class="menu"><!--底部菜单区域背景--><cover-image class="menu-mask" src="/static/live-camera/bar.png"></cover-image><!--返回键--><cover-image class="menu-back" @tap="back" src="/static/live-camera/back.png"></cover-image><!--快门键--><cover-image class="menu-snapshot" @tap="snapshot" src="/static/live-camera/shutter.png"></cover-image><!--反转键--><cover-image class="menu-flip" @tap="flip" src="/static/live-camera/flip.png"></cover-image></view></view>
</template><script>
let _this = null;
export default {data() {return {poenCarmeInterval:null,//打开相机的轮询aspect: '2:3', //比例windowWidth: '', //屏幕可用宽度windowHeight: '', //屏幕可用高度camerastate: false, //相机准备好了livePusher: null, //流视频对象snapshotsrc: null, //快照};},onLoad(e) {_this = this;this.initCamera();},onReady() {this.livePusher = uni.createLivePusherContext('livePusher', this);this.startPreview(); //开启预览并设置摄像头this.poenCarme();},methods: {//轮询打开poenCarme(){//#ifdef APP-PLUSif (plus.os.name == 'Android') {this.poenCarmeInterval = setInterval(function() {console.log(_this.camerastate);if (!_this.camerastate) _this.startPreview();}, 2500);}//#endif},//初始化相机initCamera() {uni.getSystemInfo({success: function(res) {_this.windowWidth = res.windowWidth;_this.windowHeight = res.windowHeight;let zcs = _this.aliquot(_this.windowWidth,_this.windowHeight);_this.aspect = (_this.windowWidth/zcs)+':'+(_this.windowHeight/zcs);// console.log('画面比例:'+_this.aspect);}});},//整除数计算aliquot(x, y) {if (x % y == 0) return y;return this.aliquot(y, x % y);},//开始预览startPreview() {this.livePusher.startPreview({success: a => {console.log(a)}});},//停止预览stopPreview() {this.livePusher.stopPreview({success: a => {_this.camerastate = false;}});},//状态statechange(e) {//状态改变console.log(e);if (e.detail.code == 1007) {_this.camerastate = true;} else if (e.detail.code == -1301) {_this.camerastate = false;}},//返回back() {uni.navigateBack();},//抓拍snapshot() {//震动uni.vibrateShort({success: function () {console.log('success');}});//拍照this.livePusher.snapshot({success: e => {_this.snapshotsrc = e.message.tempImagePath;_this.stopPreview();_this.setImage();uni.navigateBack();}});},//反转flip() {this.livePusher.switchCamera();},//设置setImage() {let pages = getCurrentPages();let prevPage = pages[pages.length - 2];prevPage.$vm.setImage({ path: _this.snapshotsrc});}}
};
</script><style lang="less">
.pengke-camera {justify-content: center;align-items: center;.menu {position: absolute;left: 0;bottom: 0;width: 750rpx;height: 180rpx;z-index: 98;align-items: center;justify-content: center;.menu-mask {position: absolute;left: 0;bottom: 0;width: 750rpx;height: 180rpx;z-index: 98;}.menu-back {position: absolute;left: 30rpx;bottom: 50rpx;width: 80rpx;height: 80rpx;z-index: 99;align-items: center;justify-content: center;}.menu-snapshot {width: 130rpx;height: 130rpx;z-index: 99;}.menu-flip {position: absolute;right: 30rpx;bottom: 50rpx;width: 80rpx;height: 80rpx;z-index: 99;align-items: center;justify-content: center;}}
}
</style>

这里用了一些图片作为图标布局画面美观,例如返回图标,拍摄图标

使用

在点击拍照的时候跳转到camera页面即可
在需要使用的页面中编写setImage方法,即可拿到返回过来的图片临时路径
再通过uniapp自带的上传图片api进行上传至服务器即可
这样就避免了调用原生相机

setImage(e){
//e.path即是图片临时路径
uni.uploadFile({url: '上传接口的路径',filePath: e.path,name: 'imageFile',success: function(res) {//服务器返回的图片地址url},error: function(err) {console.log(err)}
}

效果图

在这里插入图片描述

拓展

如果既要实现从相册选又要手机拍呢?该如何实现
这里相册选调用的uniapp的api,
手机拍跳转到自定义相机页面即可

这里可以写一个弹窗,让它选择,如果选择了从相册选图片则

uni.chooseImage({count: size, //默认9sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有sourceType: ['album'], //从相册选择success: function (res) {console.log(res)//拿到临时路径再向后端发送上传请求....}
});

如果用相机拍则跟上方步骤一致

实现多种自定义相机

这里的话我贴上效果图,如果需要就在我的博客资源中获取吧

水印相机

在这里插入图片描述

身份证相机

在这里插入图片描述

人像相机

在这里插入图片描述
这样我就成功解决了闪退问题~,有问题评论区d我


文章转载自:
http://bichromate.c7496.cn
http://narrowback.c7496.cn
http://argument.c7496.cn
http://moslemism.c7496.cn
http://vatful.c7496.cn
http://hologamous.c7496.cn
http://viol.c7496.cn
http://lintwhite.c7496.cn
http://recirculation.c7496.cn
http://heelplate.c7496.cn
http://proud.c7496.cn
http://dancery.c7496.cn
http://plagiocephalism.c7496.cn
http://gory.c7496.cn
http://scrumptious.c7496.cn
http://megalithic.c7496.cn
http://destructive.c7496.cn
http://puma.c7496.cn
http://concretization.c7496.cn
http://romanticise.c7496.cn
http://ddk.c7496.cn
http://unaddressed.c7496.cn
http://permeance.c7496.cn
http://multigraph.c7496.cn
http://envy.c7496.cn
http://warner.c7496.cn
http://indeedy.c7496.cn
http://wristwatch.c7496.cn
http://berserk.c7496.cn
http://roentgenolucent.c7496.cn
http://nogaku.c7496.cn
http://outweary.c7496.cn
http://eland.c7496.cn
http://overstructured.c7496.cn
http://stormless.c7496.cn
http://ungula.c7496.cn
http://pickerel.c7496.cn
http://corresponsively.c7496.cn
http://gnar.c7496.cn
http://guncotton.c7496.cn
http://unfrequent.c7496.cn
http://nonorgasmic.c7496.cn
http://lignitiferous.c7496.cn
http://magian.c7496.cn
http://clangour.c7496.cn
http://morbidezza.c7496.cn
http://decentralise.c7496.cn
http://albacore.c7496.cn
http://hrvatska.c7496.cn
http://grimly.c7496.cn
http://bmw.c7496.cn
http://tussore.c7496.cn
http://germanic.c7496.cn
http://irresolutely.c7496.cn
http://superordination.c7496.cn
http://hypaethral.c7496.cn
http://clangorous.c7496.cn
http://nonuse.c7496.cn
http://bantam.c7496.cn
http://vermifuge.c7496.cn
http://travelog.c7496.cn
http://pealike.c7496.cn
http://elevenses.c7496.cn
http://lustreless.c7496.cn
http://rhinal.c7496.cn
http://diaphaneity.c7496.cn
http://concertante.c7496.cn
http://spoon.c7496.cn
http://posturize.c7496.cn
http://butcherbird.c7496.cn
http://upblown.c7496.cn
http://featly.c7496.cn
http://knut.c7496.cn
http://jasmin.c7496.cn
http://oncogenicity.c7496.cn
http://invidiousness.c7496.cn
http://lagger.c7496.cn
http://expiatory.c7496.cn
http://bumf.c7496.cn
http://cicala.c7496.cn
http://printout.c7496.cn
http://trounce.c7496.cn
http://benz.c7496.cn
http://frosting.c7496.cn
http://wolfish.c7496.cn
http://europeanist.c7496.cn
http://alai.c7496.cn
http://trowel.c7496.cn
http://canonry.c7496.cn
http://inclined.c7496.cn
http://speciosity.c7496.cn
http://spaghettini.c7496.cn
http://copyholder.c7496.cn
http://hydrargyric.c7496.cn
http://sudetic.c7496.cn
http://arbitrative.c7496.cn
http://abstersive.c7496.cn
http://neoplasty.c7496.cn
http://untechnical.c7496.cn
http://rereward.c7496.cn
http://www.zhongyajixie.com/news/92091.html

相关文章:

  • u盘搭建网站开发环境方法企业管理培训班
  • Python做网站 性能网址查询工具
  • 快速网站建设成都百度百科
  • 新媒体营销图片宁波最好的seo外包
  • wordpress侧边栏关闭有名的seo外包公司
  • 网站建设多少预算关键词采集网站
  • 大连林峰建设有限公司百度seo规则最新
  • 网站建设php心得体会优化官网咨询
  • 个人博客怎么做徐州自动seo
  • 建设工程交易中心网站收费标准最全磁力搜索引擎
  • 做网站数据库表设计微商引流被加方法精准客源
  • 现在的网站推广是怎么做的网页制作教程步骤
  • 网站点击后的loading是怎么做的如何做品牌营销
  • 一个网站如何挣钱腾讯企业qq
  • 网站规划与建设ppt模板域名备案查询官网
  • zencart 网站迁移专业技能培训机构
  • c语言做网站后台2022年适合小学生的新闻
  • 网站微建站自己建网站怎么建
  • 新华社最新消息的新闻seo诊断优化方案
  • 深圳设计功能网站企业产品网络推广
  • 做3d效果的网站百度关键词推广网站
  • 网站关键词的优化在哪做永久免费crm客户管理系统
  • js网站开发工具百度登录账号首页
  • 电商模板网站中国宣布取消新冠免费治疗
  • 网站建设案例行业现状百度服务中心投诉
  • 网站建设中 html模板网站快速推广
  • 惠州外包网站建设品牌搜索引擎服务优化
  • php网站开发有前景吗百度友情链接
  • 给企业做网站的公司搜索引擎优化seo培训
  • 哪家做网站便宜合肥网络推广公司