Beh*_*nam 2 camera resize ionic-framework ionic3
我想减小相机 API 拍摄的图像的大小,但质量降低并不好。最好的办法是降低分辨率,但我不想为所有图像使用目标宽度和高度。
例如,我希望图像宽度为 1280 并且图像高度按比例自动更改,但在 API 中我应该使用精确的宽度和高度。
如何通过图像比例更改高度动态???
现在,我使用以下代码:
this.camera.getPicture({
quality: 60,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: sourceType,
mediaType: this.camera.MediaType.PICTURE,
targetWidth: 1280,
targetHeight: 1280,
encodingType: this.camera.EncodingType.JPEG,
saveToPhotoAlbum: (source === PictureSource.CAMERA),
allowEdit: true
})
Run Code Online (Sandbox Code Playgroud)
使用 Cordova 插件中的这些选项:
targetWidth:缩放图像的宽度(以像素为单位)。必须与targetHeight一起使用。保持纵横比。(数字)
targetHeight : 缩放图像的像素高度。必须与targetWidth一起使用。保持纵横比。(数字)
像这样
var options = {
quality: 100,
sourceType: sourceType,
saveToPhotoAlbum: false,
correctOrientation: true,
destinationType: this.camera.DestinationType.DATA_URL,
targetWidth: 400,
targetHeight: 400,
};
// Get the data of an image
this.camera.getPicture(options).then((imageData) => {
//use the imageData as required.
}, (err) => {
}).catch((error) => {
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10671 次 |
| 最近记录: |