mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-02-24 07:12:54 +08:00
parent
2a7469e065
commit
7551778e13
@ -23,7 +23,7 @@ var HIGHEST_POSSIBLE_Z_INDEX = 2147483647;
|
|||||||
|
|
||||||
function takePicture(success, error, opts) {
|
function takePicture(success, error, opts) {
|
||||||
if (opts && opts[2] === 1) {
|
if (opts && opts[2] === 1) {
|
||||||
capture(success, error);
|
capture(success, error, opts);
|
||||||
} else {
|
} else {
|
||||||
var input = document.createElement('input');
|
var input = document.createElement('input');
|
||||||
input.style.position = 'relative';
|
input.style.position = 'relative';
|
||||||
@ -48,8 +48,13 @@ function takePicture(success, error, opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function capture(success, errorCallback) {
|
function capture(success, errorCallback, opts) {
|
||||||
var localMediaStream;
|
var localMediaStream;
|
||||||
|
var targetWidth = opts[3];
|
||||||
|
var targetHeight = opts[4];
|
||||||
|
|
||||||
|
targetWidth = targetWidth == -1?320:targetWidth;
|
||||||
|
targetHeight = targetHeight == -1?240:targetHeight;
|
||||||
|
|
||||||
var video = document.createElement('video');
|
var video = document.createElement('video');
|
||||||
var button = document.createElement('button');
|
var button = document.createElement('button');
|
||||||
@ -59,14 +64,16 @@ function capture(success, errorCallback) {
|
|||||||
parent.appendChild(video);
|
parent.appendChild(video);
|
||||||
parent.appendChild(button);
|
parent.appendChild(button);
|
||||||
|
|
||||||
video.width = 320;
|
video.width = targetWidth;
|
||||||
video.height = 240;
|
video.height = targetHeight;
|
||||||
button.innerHTML = 'Capture!';
|
button.innerHTML = 'Capture!';
|
||||||
|
|
||||||
button.onclick = function() {
|
button.onclick = function() {
|
||||||
// create a canvas and capture a frame from video stream
|
// create a canvas and capture a frame from video stream
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
canvas.getContext('2d').drawImage(video, 0, 0, 320, 240);
|
canvas.width = targetWidth;
|
||||||
|
canvas.height = targetHeight;
|
||||||
|
canvas.getContext('2d').drawImage(video, 0, 0, targetWidth, targetHeight);
|
||||||
|
|
||||||
// convert image stored in canvas to base64 encoded image
|
// convert image stored in canvas to base64 encoded image
|
||||||
var imageData = canvas.toDataURL('image/png');
|
var imageData = canvas.toDataURL('image/png');
|
||||||
|
Loading…
Reference in New Issue
Block a user