即使质量为 100,Cordova 相机 getPicture 也是无损压缩
Cordova camera getPicture is lossless compressing even when quality is 100
你好朋友在我的项目中,我能够通过相机或画廊捕捉图像图像文件的大小根据相机或用户选择的质量而变化到 5-6 MB image.Then 我必须上传到服务器。
要求是,在将文件上传到远程服务器之前,我想对图像应用无损压缩以将文件大小减小到 2-3MB,这样可以节省用户和我的服务器的互联网成本 space 还有。
不使用 resize
图片。我怎样才能做到这一点?。
我让用户上传一张图片。这是我的代码。
$scope.addImage = function (source) {
$rootScope.ionPopup.close();
var src = Camera.PictureSourceType.CAMERA
if (source == 'PHOTOLIBRARY')
src = Camera.PictureSourceType.PHOTOLIBRARY
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: src,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 350,
targetHeight: 350,
//popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function (imageData) {
uploadImage(imageData);
}, function (err) {
// error
});
};
var uploadImage = function (imageData) {
$scope.orderImages.push(imageData);
$scope.orderImagesList.push({ImageString: imageData});
};
imageData
是base64编码后的图片
如何压缩该 base64 编码图像?
谁能帮帮我!
targetHeight
和 targetWidth
选项应该会改变生成的文件大小。我最近使用:
quality: 90,
targetWidth: 900,
targetHeight: 900,
将 10MB 的巨大图像文件缩小到大约 200KB。请记住:
Photos selected from the device's gallery are not downscaled to a
lower quality, even if a quality parameter is specified.
来源:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/index.html
你好朋友在我的项目中,我能够通过相机或画廊捕捉图像图像文件的大小根据相机或用户选择的质量而变化到 5-6 MB image.Then 我必须上传到服务器。
要求是,在将文件上传到远程服务器之前,我想对图像应用无损压缩以将文件大小减小到 2-3MB,这样可以节省用户和我的服务器的互联网成本 space 还有。
不使用 resize
图片。我怎样才能做到这一点?。
我让用户上传一张图片。这是我的代码。
$scope.addImage = function (source) {
$rootScope.ionPopup.close();
var src = Camera.PictureSourceType.CAMERA
if (source == 'PHOTOLIBRARY')
src = Camera.PictureSourceType.PHOTOLIBRARY
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: src,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 350,
targetHeight: 350,
//popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function (imageData) {
uploadImage(imageData);
}, function (err) {
// error
});
};
var uploadImage = function (imageData) {
$scope.orderImages.push(imageData);
$scope.orderImagesList.push({ImageString: imageData});
};
imageData
是base64编码后的图片
如何压缩该 base64 编码图像?
谁能帮帮我!
targetHeight
和 targetWidth
选项应该会改变生成的文件大小。我最近使用:
quality: 90,
targetWidth: 900,
targetHeight: 900,
将 10MB 的巨大图像文件缩小到大约 200KB。请记住:
Photos selected from the device's gallery are not downscaled to a lower quality, even if a quality parameter is specified.
来源:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/index.html