2011-09-06 10 views
6

PhoneGapのドキュメントにあるcamera.getPictureの完全な例に基づいてテストアプリを構築できました。それは私が写真を撮るかギャラリーから写真を取り出してdivに配置することを可能にします。PhoneGapを使用してデバイスの画像ギャラリーから複数の写真を選択

しかし、私はギャラリーから複数の画像を選択し、それぞれのdivに配置することができます。これを達成する方法を誰かが正しい方向に向けることができますか?

ありがとうございました。ここで

は、私が使用しているのjavascriptです:

var pictureSource; // picture source 
var destinationType; // sets the format of returned value 

// 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; 
} 

// Called when a photo is successfully retrieved 
function onPhotoDataSuccess(imageData) { 
    var largeImage = document.getElementById('largeImage'); 
    largeImage.style.display = 'block'; 
    largeImage.src = "data:image/jpeg;base64," + imageData; 
} 


function onPhotoURISuccess(imageURI) { 
    var largeImage = document.getElementById('largeImage'); 
    largeImage.style.display = 'block'; 
    largeImage.src = imageURI; 
} 

// A button will call this function 
function capturePhoto() { 
    //add new div 

    var newPhoto = document.createElement("div"); 
    newPhoto.id = "div";   
    newPhoto.className ="photo"; 
    newPhoto.innerHTML = "<img id='largeImage' src='' />"; 
    document.getElementById("photos").appendChild(newPhoto); 


    // Take picture using device camera and retrieve image as base64-encoded string 
    navigator.camera.getPicture(onPhotoDataSuccess, onPhotoURISuccess, onFail, { quality: 50 }); 
} 

// A button will call this function 
function getPhoto(source) { 
    //add new div 



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


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

私は同じを探しています - あなたはこれを理解するために起こるのですか? – woolyninja

答えて

0

あなたは、すべての写真が撮影された後、動的にdiv要素を作成する必要があります。 あなたの成功コールバックはこのようなものになるだろう:

function onPhotoDataSuccess(imageData) { 
    // the following is all one line. 
    document.getElementById("photos").innerHTML+= 
    "<div>\ 
     <img src=\"data:image/jpeg;base64,"+imageData+"\">\ 
    </div>"; 
} 

で複数の画像を選択するためのサポートがないのPhoneGap 3.5の時点で、あなたはこの

#photos > div { 
    width: 100px; 
    margin:10px; 
    float:left; 
} 
2

のようなものを使用してCSSを経由して、すべてのIMGSのスタイルを設定することができます同じ時間。これを行うために、ネイティブコードで動作するプラグインを作成または検索する必要があります。 Phonegap開発計画で説明されている問題があります。 https://issues.apache.org/jira/browse/CB-1215

私はこれもやっています。ここにAndroidソリューションのリンクがあります。

http://webcache.googleusercontent.com/search?q=cache:http://www.technotalkative.com/android-select-multiple-photos-from-gallery/

関連する問題