2011-09-06 4 views
6

PhoneGap의 설명서에서 camera.getPicture 전체 예제를 기반으로 테스트 응용 프로그램을 만들 수있었습니다. 갤러리에서 사진을 가져 오거나 사진을 검색하여 div에 배치 할 수 있습니다.PhoneGap을 사용하여 장치의 이미지 갤러리에서 여러 사진 선택

그러나 갤러리에서 여러 이미지를 선택하고 각각의 div에 각각 배치 할 수 있기를 원합니다. 누구든지이 일을 수행하는 법을 배우기 위해 올바른 방향으로 나를 가리킬 수 있습니까?

감사합니다. 여기

내가 사용하고 자바 스크립트입니다 :

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

당신은 모든 사진을 찍은 후 동적으로 사업부를 작성해야합니다.

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

다음에 여러 이미지를 선택에 대한 지원이없는 폰갭 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/

관련 문제