angular - 相机,CameraOptions 在我的移动应用程序中不起作用
问题描述
我正在开发一个移动应用程序,我想打开图库以选择一张图片,但是当单击按钮时,应用程序没有任何作用,甚至没有抛出错误,这是我的代码:
photos: any = '';
base64Image = '';
async agregarImg() {
const actionSheet = await this.actionSheetController.create({
header: 'Seleccionar medio',
buttons: [{
text: 'Cámara',
icon: 'camera',
handler: () => {
this.takePicture(CameraSource.Camera, false)
}
}, {
text: 'Galería',
icon: !this.platform.is('ios') ? 'ios-images-outline' : 'images-outline',
handler: () => {
this.openGallery();
}
}]
});
await actionSheet.present();
}
openGallery() {
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
mediaType: this.camera.MediaType.PICTURE,
encodingType: this.camera.EncodingType.JPEG,
correctOrientation: true,
allowEdit: false,
}
this.camera.getPicture(options).then((imageData) => {
this.base64Image = 'data:image/jpeg;base64,' + imageData;
this.photos.push(this.base64Image);
this.photos.reverse();
}, (err) => {
console.log(err);
})
}
我读到了这个问题,可能插件会发生这种情况,这在 Android 上不能完美运行。我使用这个插件: import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
解决方案
从文档中获取,我建议进行以下更改
openGallery() {
const options: CameraOptions = {
...
destinationType: this.camera.DestinationType. FILE_URI,
pictureSourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
...
推荐阅读
- .net - 如果未使用 wyBuild 安装 .NET 4,则自行升级以回滚
- ios - 裁剪 UIImage 使其在保存时逆时针旋转 90º
- php - PHP & Angular 2 - 带有自己的 API 和数据库的“实时”直接消息传递
- python-2.7 - 使用多处理库时出错:“为关键字参数 'x' 获取了多个值”
- architecture - 记录事件驱动的架构
- c# - 具有三个级别的wpf Treeview
- ios - UILabel 多行不工作
- python - 依次运行两个 python 脚本
- python - 如何在 Python 中将 Caesar 密码转换回正常状态?
- java - Selenium WebDriver 如果条件消耗大量时间