我可以查看我的服务器图像,从我的设备的相机拍摄的图像,但真相重量为5.4 MB,质量非常好。我想知道是否有某种参数要声明质量或至少文件的重量较低。
Camera.getPicture().then(function(imageURI) {
$scope.imagen = imageURI;
$scope.lastPhoto = imageURI;
$scope.mostrar_form = true;
$scope.mostrar_boton_view = false;
google.maps.event.addDomListener(window, 'load', initialize);
initialize();
document.getElementById('buton_refresh').click();
$( "#buton_refresh" ).trigger( "click" );
}, function() {
$scope.mostrar_boton_view = true;
$ionicHistory.goBack();
}, {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true,
correctOrientation: true
})
功能上传图片:
$scope.publicarView = function(){
var server = URL_BASE+'addView/'+sessionService.get("user_id")+"/"+$scope.data.content+"/null/"+$scope.latitud+"/"+$scope.longitud+"/"+1;
var trustAllHosts = true;
var ftOptions = new FileUploadOptions();
ftOptions.fileKey = 'file';
ftOptions.fileName = $scope.imagen.substr($scope.imagen.lastIndexOf('/') + 1);
ftOptions.mimeType = 'image/jpeg';
ftOptions.httpMethod = 'POST';
console.log(ftOptions);
$cordovaFileTransfer.upload(encodeURI(server), $scope.imagen, ftOptions, trustAllHosts)
.then(function(result) {
console.log(result)
}, function(err) {
// Error
console.log(err);
}, function (progress) {
});
}
答案 0 :(得分:1)
Cordova Camera插件可与以下参数一起使用:
var options = {
quality: 50,
destinationType: Camera.DestinationType.NATIVE_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 700,
targetHeight: 700,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
以下参数会对尺寸产生影响:
quality: 50,
targetWidth: 700,
targetHeight: 700,
请在此处查看官方文档:https://github.com/apache/cordova-plugin-camera
例如,我拍照的代码看起来像是;
var options = {
quality: 50,
destinationType: Camera.DestinationType.NATIVE_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 700,
targetHeight: 700,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
d.resolve( { "img" : imageData });
}, function(err) {
d.reject(err);
});