如何使用 Ionic Framework 捕获图像并保存到图库中
How to capture image & save into the Gallery with Ionic Framework
如何使用 ionic 框架捕获图像并将其保存到图库?
我尝试了几种选择,但它不适用于 Android 的 Marshmallow 版本。
添加 cordova-plugin-camera 插件
命令:ionic plugin add cordova-plugin-camera
HTML
<span class="button" ng-click = captureImage();> Capture </span>
参考:
http://ngcordova.com/docs/plugins/camera/
JS
.controller('cameraCtrl', function($scope,$cordovaCamera) {
$scope.captureImage = function() {
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
$scope.imgURI = "data:image/jpeg;base64," + imageData;
}, function(err) {
console.log("An error Occured");
});
}
});
cordova-plugin-camera (For capturing Image)
cordova-plugin-file-transfer (For uploading)
cordova-plugin-file (For accessing device’s files and directories )
根据您的要求使用这些插件。 http://ngcordova.com/docs/plugins/camera/
之后如果你遇到 imgae 不显示问题,那么使用这个
cordova plugin add cordova-plugin-refresh-gallery
如何使用 ionic 框架捕获图像并将其保存到图库?
我尝试了几种选择,但它不适用于 Android 的 Marshmallow 版本。
添加 cordova-plugin-camera 插件
命令:ionic plugin add cordova-plugin-camera
HTML
<span class="button" ng-click = captureImage();> Capture </span>
参考: http://ngcordova.com/docs/plugins/camera/
JS
.controller('cameraCtrl', function($scope,$cordovaCamera) {
$scope.captureImage = function() {
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
$scope.imgURI = "data:image/jpeg;base64," + imageData;
}, function(err) {
console.log("An error Occured");
});
}
});
cordova-plugin-camera (For capturing Image)
cordova-plugin-file-transfer (For uploading)
cordova-plugin-file (For accessing device’s files and directories )
根据您的要求使用这些插件。 http://ngcordova.com/docs/plugins/camera/
之后如果你遇到 imgae 不显示问题,那么使用这个
cordova plugin add cordova-plugin-refresh-gallery