I'm trying to use the Camera, and I would like to know if you have any exemple on how to make it work on both web / native.
我正在尝试使用相机,我想知道你是否有任何关于如何使它在web / native上工作的例子。
I have this piece of code, borrowed from the ng-cordova doc :
我有这段代码,借用了ng-cordova doc:
$scope.takePicture = function() {
var options = {
quality: 75,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 100,
targetHeight: 100,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
// Success! Image data is here
}, function(err) {
// An error occured. Show a message to the user
});
}
When I use it, it works well with my device, but catch an error with the web version
当我使用它时,它适用于我的设备,但在Web版本中发现错误
ReferenceError: Camera is not defined
That's why I ask if you have any good way to do that. I could simulate a click on an hidden input, but it doesn't look pretty. If you have any idea :)
这就是为什么我问你是否有任何好的方法来做到这一点。我可以模拟隐藏输入的点击,但看起来不漂亮。如果你有任何想法:)
1 个解决方案
#1
4
You could provide an implementation for the camera access for both Cordova and standard browser. The standard browser implementation could be realized using this
您可以为Cordova和标准浏览器提供摄像头访问的实现。可以使用此实现标准浏览器实现
http://www.html5rocks.com/en/tutorials/getusermedia/intro/
http://www.html5rocks.com/en/tutorials/getusermedia/intro/
W3选秀
and to check, whether you're running in an app or in browser, you could use
并检查,无论您是在应用程序中运行还是在浏览器中运行,都可以使用
ionic.Platform.platform()
documented here
记录在这里
#1
4
You could provide an implementation for the camera access for both Cordova and standard browser. The standard browser implementation could be realized using this
您可以为Cordova和标准浏览器提供摄像头访问的实现。可以使用此实现标准浏览器实现
http://www.html5rocks.com/en/tutorials/getusermedia/intro/
http://www.html5rocks.com/en/tutorials/getusermedia/intro/
W3选秀
and to check, whether you're running in an app or in browser, you could use
并检查,无论您是在应用程序中运行还是在浏览器中运行,都可以使用
ionic.Platform.platform()
documented here
记录在这里