作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想减小相机 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
})
最佳答案
使用 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) => {
})
关于ionic-framework - 如何在没有质量降低和目标宽度和高度的情况下在 Ionic 3 中调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46150790/
我是一名优秀的程序员,十分优秀!