2012-01-18 11 views
5

アクセス画像

var pictureSource; // picture source 
    var destinationType; // sets the format of returned value 
    var photoid=window.localStorage.getItem("photoid"); 
    var photoData=null; 
    // Wait for PhoneGap to connect with the device 
    // 
    document.addEventListener("deviceready",onDeviceReady,false); 

    // PhoneGap is ready to be used! 
    // 
    function onDeviceReady() { 
     pictureSource=navigator.camera.PictureSourceType; 
     destinationType=navigator.camera.DestinationType; 

    } 

    // A button will call this function 
    // 
    function getPhoto(source) { 
     alert("Entered sd card"); 
     // Retrieve image file location from specified source 
     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, 
            destinationType: destinationType.FILE_URI, 
            sourceType: source }); 
    } 

    function onPhotoDataSuccess(imageData) { 
     console.log(imageData); 

     // Get image handle 
     var smallImage = document.getElementById('photos'); 

     // Unhide image elements 
     // 
     smallImage.style.display = 'block'; 

     // Show the captured photo 
     // The inline CSS rules are used to resize the image 
     // 
     smallImage.src = "data:image/jpeg;base64," + imageData; 
     alert(imageData); 
     photoData = imageData; 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); 
    } 

    function gotFS(fileSystem) { 
     fileSystem.root.getFile("/sdcard/external_sd/"+photoid+".jpg", null, gotFileEntry, fail); 
    } 

    function gotFileWriter(writer) { 
     writer.onwrite = function(evt) { 
      alert("write success"); 
     }; 
     writer.write(photoData); 
    } 

    function fail(error) { 
     alert(error.code); 
    } 


    /* function onPhotoURISuccess(imageURI) { 
     // Uncomment to view the image file URI 
     console.log(imageURI); 
     alert("photo captured"); 
     uploadPhoto(imageURI); 
    } */ 

    /* function getPhoto(source) { 
     // Retrieve image file location from specified source 
     navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
            destinationType: destinationType, 
            sourceType: source }); 
    } */ 

    // Called if something bad happens. 
    // 
    function onFail(message) { 
     alert('Failed because: ' + message); 
    } 

私は、SDカード内のデータにアクセスするために上記のコードを使用しています。しかし、今私がする必要があるのは、そこにあるイメージのパスを取得し、パスにアクセスしてそのイメージを表示できるdiffオブジェクトに配置することです。私はそれについてどうやって行くのかについての手がかりはない。 何か助けていただければ幸いです。

+0

ユーザーが選択した画像のパス、またはすべての画像へのパスが必要ですか? – ghostCoder

+0

それは何を達成したいのか明確ではありません。 pls編集し、少し明確にする。ユースケースの例は良いでしょう。 – ghostCoder

+0

私は、SDカード内のすべての画像へのパスを含むオブジェクトを作成する必要があります。つまり、イメージパスを持ち、すべてのイメージを開くことができるはずの別のオブジェクトを介してすべてのsdカードイメージにアクセスできる必要があります。 – Khush

答えて

2

あなたができることは、開発中のプラットフォーム用のphonegapプラグインを作成することです。私はそれがアンドロイドだと仮定します。その後、 Writing android plugins.
あなたは、プラグインをプラグインを呼び出すためにPhonegap.execを呼び出し、

Environment.getExternalStorageDirectory().getAbsolutePath() 

を通じてSDカードのパスを取得し、すべての.jpgと.pngのファイルを取得して返すために、基本的な検索を行いますファイルのすべてのパスのjson。

+0

これはオプションの1つです。しかし、今探しているのは、私はSDカードに存在する画像のリストを取得できますか?私はアンドロイドとIOSのために働く同じコードをします。 – Khush

+0

あなたはこの仕事のためにiphone nアンドロイドのために別々のプラグインを書く必要があります。私は簡単に記載された方法で画像のリストを取得することができます。 – ghostCoder

+0

私はSDカード画像のための別のギャラリーを作り、それらを表示するための他の選択肢がありますか? – Khush

関連する問題