2017-07-07 19 views
0

イオン2を使用して画像を選択するためにアンドロイドのフォトライブラリを開こうとしています。 ここではカメラプラグインが使用されている家庭のコードです。画像選択はイオン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ボタンをクリックすると、アンドロイドのライブラリが開かれたが、私は、画像を選択すると、空白の画面が表示されます約8秒間、それ以降、それは表示されるルートページです。それから私は私のページで選択されたイメージを見ることができません。 誰かが助けることができますか?

答えて

0

設定オプション

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 
    } 
+0

おかげ@Iris_geekなどの写真を選択します。しかし、私はそれを試した。それはまったく動作しません。私はコードを編集しました。あなたはそれをポストで見ることができます。 –

+0

私はちょうどあなたのコードをコピーして、それは正常に動作しています。あなたがどこを間違えているのか分かりません。 –

+0

ステータスバープラグインがインストールされていますか? –

関連する問題