gpt4 book ai didi

javascript - PhoneGap 相机,无法读取未定义的属性 'getPicture'

转载 作者:可可西里 更新时间:2023-11-01 13:33:10 26 4
gpt4 key购买 nike

我正在尝试让 Camera API 在我的 PhoneGap android 应用程序中工作,但我一直收到此错误

"Cannot read property 'getPicture' of undefined".

现在我已经检查了 StackOverflow 上的无数答案和整个网络的教程,并尝试了那里的所有答案(没有运气),但我似乎找不到问题。

这是调用函数的按钮

<button type="button" class="btn btn-primary" ng-click="getPic()">Camera</button>

这是处理相机的 Controller

myApp.controller('EditProfileCtrl', function ($scope, $http, navigateFactory) {
$scope.getPic = function () {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 60,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: 1
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed beause' + message);
}
};
});

如果需要任何其他信息,请发表评论。我们将不胜感激任何帮助。

编辑:所以在听从 Aravin 的建议后,我添加了 <script src="cordova.js"></script>现在至少看起来有些事情正在发生,但现在我在我的 eclipse logcat 中收到这些错误:

I/System.out(3871): Error adding plugin org.apache.cordova.CameraLauncher D/PluginManager(3871): exec() call to unknown plugin: Camera

最佳答案

总的解决方法如下..

您需要在 html 页面中编写所有代码。

<body>
<div data-role="page">
<script type="text/javascript">
function getPhotoFromCamera() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 50,
sourceType: navigator.camera.PictureSourceType.CAMERA,
destinationType: navigator.camera.DestinationType.DATA_URL,
});
}
function onPhotoDataSuccess(imageData){
var image = document.getElementById('image');
image.style.display = 'block';
image.src = "data:image/jpeg;base64,"+imageData;
}
function getPhotoFromAlbum(){
navigator.camera.getPicture(onPhotoURISuccess, onFail,{
quality: 50,
sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType: navigator.camera.DestinationType.FILE_URI
});
}
function onPhotoURISuccess(imageURI){
var image = document.getElementById('image');
image.style.display = 'block';
image.src = imageURI;
}
function onFail(message){
alert('Failed because:' + message);
}
</script>

<div data-role="header" style="height:36px;">
<h1>Write New</h1>
<a href="#" data-icon="arrow-l" data-rel="back">Back</a>
</div>

<button onclick="getPhotoFromCamera();">Launch Camera</button>
<button onclick="getPhotoFromAlbum();">Goto Picture Gallery</button>
<div>
<img id="image" style="display:none;width;290px;height:210px;" src = ""/>
</div>

</div>
<script type="text/javascript" src="cordova.js"></script>

</body>

关于javascript - PhoneGap 相机,无法读取未定义的属性 'getPicture',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24629092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com