flash jquery 调用摄像头 vue chrome49浏览器
flash jquery 调用摄像头 vue chrome49浏览器
这个摄像头,不能一个页面加载多个,只能一个页面显示一次,所以 调用的时候,记得加v-if 把组件销毁,然后从新加载新的
<!--
* @description 摄像头vue版实例
* @fileName cameraObject.vue
* @author 彭成刚
* @date // ::
* @version V1.0.0
!-->
<template>
<div> <div id="webcam"></div>
<!--<button @click="jieping">截屏</button>-->
<div style="color:red; margin: 10px;">点击即可启用 Adobe Flash Player(拍照功能将启用Flash,第一次启用将会刷新页面,导致数据丢失,建议返回表单页面保存数据后开启拍照功能。)</div> <Button type='primary'
@click="handleCamera"
style="margin-bottom:5px; margin-right:5px;">拍照</Button><!--icon="md-camera"-->
<Button type='warning'
@click="leftRotate"
:disabled="buttonDisabled"
style="margin-bottom:5px; margin-right:5px;">逆旋转</Button>
<Button type='warning'
@click="rightRotate"
:disabled="buttonDisabled"
style="margin-bottom:5px;">正旋转</Button>
<!--<canvas id="canvas" width="" height=""></canvas>-->
<div>
<img ref="img" id="base64image" src='' />
</div>
</div>
</template> <script>
import jQuery from '@/../public/components/webcam/jquery.webcam'
export default {
data () {
return {
buttonDisabled: true,
timer: new Date().getTime().toString(),
picIsHave: false
}
}, components: {}, computed: {}, mounted () {
let _this = this
var pos = , ctx = null, saveCB, image = []; var canvas = document.createElement("canvas");
canvas.setAttribute('width', );
canvas.setAttribute('height', ); if (canvas.toDataURL) { ctx = canvas.getContext("2d"); image = ctx.getImageData(, , , ); saveCB = function(data) {
// console.info('data', data) var col = data.split(";");
var img = image; for(var i = ; i < ; i++) {
var tmp = parseInt(col[i]);
img.data[pos + ] = (tmp >> ) & 0xff;
img.data[pos + ] = (tmp >> ) & 0xff;
img.data[pos + ] = tmp & 0xff;
img.data[pos + ] = 0xff;
pos+= ;
} if (pos >= * * ) {
ctx.putImageData(img, , )
var base64 = canvas.toDataURL("image/png")
// console.info('canvas.toDataURL("image/png")',)
// document.getElementById('base64image').attributes('src',base64)
console.info('_this',_this)
jQuery('#base64image').attr('src',base64)
_this.buttonDisabled = false
// $.post("/upload.php", {type: "data", image: canvas.toDataURL("image/png")});
pos = ;
}
}; } else { saveCB = function(data) {
console.info('data2',data)
image.push(data); pos+= * ; if (pos >= * * ) {
console.info('data2 ok')
// $.post("/upload.php", {type: "pixel", image: image.join('|')});
pos = ;
}
};
} jQuery("#webcam").webcam({ width: ,
height: ,
mode: "callback",
swffile: "/familyMajor_web/components/webcam/jscam_canvas_only.swf", onSave: saveCB, onCapture: function () {
webcam.save();
}, debug: function (type, string) {
console.log(type + ": " + string);
}
});
}, methods: {
// 外层调用
getPicBase64 () {
let base64 = this.$refs.img.src
let ret = {
picIsHave: this.picIsHave,
base64: base64
}
return ret
},
handleCamera () {
this.picIsHave = true
webcam.capture()
},
leftRotate () {
let src = this.$refs.img.src
let edg = -
this.rotateBase64Img(src, edg, (_) => { this.$refs.img.src = _ })
},
rightRotate () {
let src = this.$refs.img.src
let edg =
this.rotateBase64Img(src, edg, (_) => { this.$refs.img.src = _ })
},
rotateBase64Img (src, edg, callback) {
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d') var imgW // 图片宽度
var imgH // 图片高度
var size // canvas初始大小 if (edg % !== ) {
console.error('旋转角度必须是90的倍数!')
// throw '旋转角度必须是90的倍数!'
}
(edg < ) && (edg = (edg % ) + )
const quadrant = (edg / ) % // 旋转象限
const cutCoor = { sx: , sy: , ex: , ey: } // 裁剪坐标 var image = new Image()
image.crossOrigin = 'anonymous'
image.src = src image.onload = function () {
imgW = image.width
imgH = image.height
size = imgW > imgH ? imgW : imgH canvas.width = size *
canvas.height = size *
switch (quadrant) {
case :
cutCoor.sx = size
cutCoor.sy = size
cutCoor.ex = size + imgW
cutCoor.ey = size + imgH
break
case :
cutCoor.sx = size - imgH
cutCoor.sy = size
cutCoor.ex = size
cutCoor.ey = size + imgW
break
case :
cutCoor.sx = size - imgW
cutCoor.sy = size - imgH
cutCoor.ex = size
cutCoor.ey = size
break
case :
cutCoor.sx = size
cutCoor.sy = size - imgW
cutCoor.ex = size + imgH
cutCoor.ey = size + imgW
break
} ctx.translate(size, size)
ctx.rotate(edg * Math.PI / )
ctx.drawImage(image, , ) var imgData = ctx.getImageData(cutCoor.sx, cutCoor.sy, cutCoor.ex, cutCoor.ey)
if (quadrant % === ) {
canvas.width = imgW
canvas.height = imgH
} else {
canvas.width = imgH
canvas.height = imgW
}
ctx.putImageData(imgData, , )
callback(canvas.toDataURL())
}
} }
} </script>
<style lang='less'> </style>
flash jquery 调用摄像头 vue chrome49浏览器的更多相关文章
- 使用vue做移动app时,调用摄像头扫描二维码
现在前端技术发展飞快,前端都能做app了,那么项目中,也会遇到调用安卓手机基层的一些功能,比如调用摄像头,完成扫描二维码功能 下面我就为大家讲解一下,我在项目中调用这功能的过程. 首先我们需要一个中间 ...
- vue实现PC端调用摄像头拍照人脸录入、移动端调用手机前置摄像头人脸录入、及图片旋转矫正、压缩上传base64格式/文件格式
进入正题 1. PC端调用摄像头拍照上传base64格式到后台,这个没什么花里胡哨的骚操作,直接看代码 (canvas + video) <template> <div> &l ...
- html5调用摄像头并拍照
随着flash被禁用,flash上传附件的方式已成为过去,现在开始用html5上传了.本片文章就是介绍如何使用html5拍照,其实挺简单的原理: 调用摄像头采集视频流,利用canvas的特性生成bas ...
- jQuery 调用jsonp实现与原理
jQuery 调用jsonp实现与原理 您的评价: 收藏该经验 阅读目录 1.客户端代码 2.服务器端 通过jQuery实现JSONP 一般的ajax是不能跨域请求的,因此需要使 ...
- HTML之调用摄像头实现拍照和摄像功能
应该有很多人知道,我们的手机里面有个功能是“抓拍入侵者”,说白了就是在解锁应用时如果我们输错了密码手机就会调用这一功能实现自动拍照. 其实在手机上还有很多我们常用的软件都有类似于这样的功能,比如微信扫 ...
- web HTML5 调用摄像头的代码
最近公司要求做一个在线拍照的功能,具体代码如下: <html> <head> <title>html5调用摄像头拍照</title> <style ...
- VS2010中使用Jquery调用Wcf服务读取数据库记录
VS2010中使用Jquery调用Wcf服务读取数据库记录 开发环境:Window Servere 2008 +SQL SERVE 2008 R2+ IIS7 +VS2010+Jquery1.3.2 ...
- 抛弃WebService,在.NET4中用 jQuery 调用 WCF
在我们之前的开发中,对于ajax程序,都是通过jQuery调用标记为[System.Web.Script.Services.ScriptService]的WebService,然后在WebServic ...
- [转]html5调用摄像头实例
原文:https://blog.csdn.net/binquan_liang/article/details/79489989 最近在学习在做HTML5的项目,看了博客上html5调用摄像头拍照的文章 ...
随机推荐
- Python中生成随机数
目录 1. random模块 1.1 设置随机种子 1.2 random模块中的方法 1.3 使用:生成整形随机数 1.3 使用:生成序列随机数 1.4 使用:生成随机实值分布 2. numpy.ra ...
- uoj#349. 【WC2018】即时战略(动态点分治)
传送门 头一次看着题解有一种咱不会\(c++\)的感觉-- 看题解吧-- //minamoto #include<bits/stdc++.h> #include "rts.h&q ...
- uoj#388. 【UNR #3】配对树(线段树合并)
传送门 先考虑一个贪心,对于一条边来说,如果当前这个序列中在它的子树中的元素个数为奇数个,那么这条边就会被一组匹配经过,否则就不会 考虑反证法,如果在这条边两边的元素个数都是偶数,那么至少有两组匹配经 ...
- pytest框架(二)
一.示例代码一 D:YOYO\ __init__.py test_class.py # content of test_class.py class TestClass: def test_one(s ...
- 一、接口测试——HTTPRunner二次开发之参数化一
目前项目中在使用开源框架HTTPRunner,时间使用过程中会用到生成随机信息的方法,如生成随机姓名.随机手机号.身份证号.姓名.地址等.以下对二次开发的过程进行简要描述. 一.需求 1.需要测试的接 ...
- P1295-创意吃鱼
题目描述 回到家中的猫猫把三桶鱼全部转移到了她那长方形大池子中,然后开始思考:到底要以何种方法吃鱼呢(猫猫就是这么可爱,吃鱼也要想好吃法 ^_*).她发现,把大池子视为01矩阵(0表示对应位置无鱼,1 ...
- 第九组 通信3班 063 OSPFv2与OSPFv3综合实验
实验目的 1. 掌握 OSPFv3(v2) 的配置方法 2. 掌握在帧中继环境下 OSPFv3 (v2)的配置方法 3. 掌握 OSPFv3(v2) NSSA 的配置方法 4. 掌握外部路由汇总的配置 ...
- 运用html常用标签和css定位等学做模仿百度导航页面
导航部分文字链接,鼠标触碰变颜色,除百度logo引用图片外,其它均代码编写.注释部分是一开始用的百度一下截图做的按钮,后来用div填充颜色写了一个按钮.效果图如下. HTML代码如下: <!DO ...
- $("body").animate({"scrollTop":top})无效的问题
问题 我在个人站点的左下角和右下角各自使用了如下代码来将页面滚动到顶部和底部: $("body").animate({scrollTop:0},800); $("body ...
- 浅谈最近公共祖先(LCA)
LCA(Least Common Ancestors),即最近公共祖先,是指在有根树中,找出某两个结点u和v最近的公共祖先. (来自百度百科) 一.倍增求LCA 预处理出距点u距离为2^0,2^1,2 ...