license: > Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Запустите приложение камеры и возвращают сведения о файлах образа.
navigator.device.capture.captureImage( CaptureCB captureSuccess, CaptureErrorCB captureError, [CaptureImageOptions options] );
Начинает асинхронную операцию для захвата изображения с помощью приложения камеры устройства. Операция позволяет пользователям захватывать более одного изображения за один сеанс.
Операции захвата заканчивается, либо когда пользователь закрывает приложение камеры, или максимальное количество записей, указанный [CaptureAudioOptions](captureAudioOptions.html).limit
достигается. Если не limit
указано значение, по умолчанию он один (1) и захвата операция прекращается после того, как пользователь захватывает отдельное изображение.
По завершении операции захвата он вызывает [CaptureCB](CaptureCB.html)
обратного вызова с массивом [MediaFile](MediaFile.html)
объектов, описывающих каждый файл образа. Если пользователь завершает операцию до захвата изображения, [CaptureErrorCB](CaptureErrorCB.html)
обратного вызова выполняется с [CaptureError](CaptureError.html)
объекта с изображением [CaptureError](CaptureError.html).CAPTURE_NO_MEDIA_FILES
код ошибки.
Вызов приложения родной камеры в то время как ваше устройство подключено через Zune не работает, и выполняет обратный вызов для ошибки.
// capture callback var captureSuccess = function(mediaFiles) { var i, path, len; for (i = 0, len = mediaFiles.length; i < len; i += 1) { path = mediaFiles[i].fullPath; // do something interesting with the file } }; // capture error callback var captureError = function(error) { navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error'); }; // start image capture navigator.device.capture.captureImage(captureSuccess, captureError, {limit:2});
<!DOCTYPE html> <html> <head> <title>Capture Image</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8" src="json2.js"></script> <script type="text/javascript" charset="utf-8"> // Called when capture operation is finished // function captureSuccess(mediaFiles) { var i, len; for (i = 0, len = mediaFiles.length; i < len; i += 1) { uploadFile(mediaFiles[i]); } } // Called if something bad happens. // function captureError(error) { var msg = 'An error occurred during capture: ' + error.code; navigator.notification.alert(msg, null, 'Uh oh!'); } // A button will call this function // function captureImage() { // Launch device camera application, // allowing user to capture up to 2 images navigator.device.capture.captureImage(captureSuccess, captureError, {limit: 2}); } // Upload files to server function uploadFile(mediaFile) { var ft = new FileTransfer(), path = mediaFile.fullPath, name = mediaFile.name; ft.upload(path, "http://my.domain.com/upload.php", function(result) { console.log('Upload success: ' + result.responseCode); console.log(result.bytesSent + ' bytes sent'); }, function(error) { console.log('Error uploading file ' + path + ': ' + error.code); }, { fileName: name }); } </script> </head> <body> <button onclick="captureImage();">Capture Image</button> <br> </body> </html>