Cordova相机插件不启动相机 [英] Cordova camera plugin not launching camera
问题描述
我创建了一个Ionic应用程序,我需要相机功能,以便用户可以拍摄照片并将其发送到Web服务。我已遵循Ionic的以下指南。
I've created an Ionic app and I need the camera functionality so that a user can take a picture and send it to a webservice. I've followed the following guide by Ionic.
基本上你只需将 cd
插入到你的应用程序中即可。
Basically you just cd
into your applicatoin
cd myApp
然后您运行
cordova plugin add org.apache.cordova.camera
插件已经安装,你可以在你的应用程序中调用它的功能(因为根据Cordova, navigator.camera
是一个全局对象)。在我的情况下,我只是在我的控制器之一,使用 ng-click
按钮单击后调用以下函数:
and once the plugin has been installed, you can invoke it's functionality where ever in your app (because according to Cordova, navigator.camera
is a global object). In my case I'm just doing it in one of my controllers where the following function gets called after a button click using ng-click
:
$scope.takePhoto = function() {
navigator.camera.getPicture(function(imageURI) {
// imageURI is the URL of the image that we can use for
// an <img> element or backgroundImage.
}, function(err) {
// Ruh-roh, something bad happened
}, cameraOptions);
}
但它什么也不做。 Ionic说我必须做一个'T',没有更多。还有什么我应该做吗?可能是编辑 config.xml
?这可能值得一提,这是我第一次尝试使用任何类型的Cordova插件。
But it does nothing.. Now I've followed what Ionic said I must do to a 'T' and nothing more. Is there anything else I should be doing? Editing the config.xml
perhaps? It's probably worth mentioning that this is the first time I've attempted in using a Cordova plugin of any sort.
推荐答案
使用以下代码解决此问题,
I just resolved this problem by using below code,
$scope.takePhoto = function() {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 75,
targetWidth: 320,
targetHeight: 320,
destinationType: 0
});
function onSuccess(imageData) {
alert('onSuccess');
console.log("data:image/jpeg;base64,"+imageData);
}
function onFail(message) {
alert('Failed because: ' + message);
}
};
imageData 是您捕获的图像的src
The imageData is the src of your captured image
这篇关于Cordova相机插件不启动相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!