图像选择不工作在离子2应用程序
问题描述:
我想打开Android的光电图库选择使用离子2的图像。 这里是使用相机插件的home.ts代码。图像选择不工作在离子2应用程序
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {Camera} from '@ionic-native/camera';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
image640:any;
constructor(public navCtrl: NavController,public camera : Camera)
{
}
openGallery()
{
var options = {
quality: 100,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
saveToPhotoAlbum: true,
correctOrientation: true,
};
this.camera.getPicture(
options
).then(
(imageData)=>
{
this.image640 = 'data:image/jpeg;base64,'+imageData;
},
(err) =>
{
console.log(err);
}
);
}
}
而且home.html的的代码如下:
<ion-header>
<ion-navbar>
<ion-title align="center">
Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<img src="image640" *ngIf="image640"/>
<Button align="center" ion-button (click)="openGallery()">Open
Gallery</Button>
</ion-content>
,但是当我在opengallery按钮点击,Android的库被打开,但是当我选择图像,黑屏出现在大约8秒钟内,并且在那之后,它是显示的根页面。然后我看不到我的页面中选定的图像。 有人可以帮忙吗?
答
设置选项
var options = {
quality: 100,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
saveToPhotoAlbum: true,
correctOrientation: true,
};
然后选择该
this.camera.getPicture(options).then((imagePath) => {
// Special handling for Android library
if (this.platform.is('android') && sourceType ===
this.camera.PictureSourceType.PHOTOLIBRARY) { //when selecting from library
//your code goes here
} else { //when capturing by camera
//your code goes here
}
感谢@Iris_geek喜欢的照片。但我试过了。它根本不起作用。我编辑了代码。你可以看到它在帖子里bab bab。 –
我刚刚复制你的代码,它工作正常。我不知道你在做错什么。 –
你是否安装了statusbar插件? –