2010-03-25 41 views
1

我是Xcode和iPhone應用程序的新手。我想從iPhone(相機或庫)中選擇一個圖像並通過ajax發送給php。從iPhone獲取圖像,使用phonegap相機api

http://wiki.phonegap.com/iPhone:-Camera-API

我使用的PhoneGap框架,Xcode的iPhone SDK版本3.1.x.點擊按鈕時,它會調用參數0或1的函數,但不會初始化攝像頭或顯示庫。

我檢查了模擬器的虛擬手機;沒有相機的圖標,但圖片專輯在那裏。

我使用了與上述鏈接相同的代碼。

我該怎麼做,什麼以及如何檢查?使用phonegap獲取照片的任何其他功能?

回答

1

它在調試控制檯中顯示此錯誤: 2010-03-25 23:36:02.337 PhoneGap [7433:207] Camera.getPicture:相機不可用。

兩者都是相同的功能Camera.getPicture的pamameter只有不同的0或1,但照片也沒有wokring!

6

相機在iPhone模擬器中不可用。在iPhone模擬器中運行時使用相冊進行測試,然後在實際的iPhone設備上測試相機。

+0

您好,是否有可能嵌入攝像頭一個div? – 2013-06-04 05:56:20

0

也不適用於我在實際的電話。被稱爲成功或失敗的功能。我在getPicture周圍放了一個try/catch,並且它捕獲了一個異常,說「異常得到圖片:ReferenceError:找不到變量:GapCam」。這在模擬器和手機上是一樣的。任何想法?

0

我遵循了PhoneGap API文檔中的示例,它適用於使用iPhone 4設備的我。這裏是我的代碼:

function take_pic(){ 
    var viewport = document.getElementById('viewport'); 
    viewport.style.display = ""; 
    navigator.camera.getPicture(dump_pic, fail, { quality: 50 }); 
} 

function dump_pic(data){ 
    var viewport = document.getElementById('viewport'); 
    console.log(data); 
    viewport.style.display = "block"; 
    viewport.style.position = "absolute"; 
    viewport.style.top = "10px"; 
    viewport.style.left = "10px"; 
    document.getElementById("test_img").src = "data:image/jpeg;base64," + data; 
} 
+0

很好...謝謝... – Mrunal 2013-04-02 16:23:05

3
// JavaScript Document //Get Picture stuff 
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, destinationType: destinationType.FILE_URI, sourceType:Camera.PictureSourceType.SAVEDPHOTOALBUM}); 

var pictureSource; // picture source 
var destinationType; // sets the format of returned value 
pictureSource=navigator.camera.PictureSourceType; 
destinationType=navigator.camera.DestinationType; 

function onPhotoURISuccess(imageURI) { 
    // Uncomment to view the image file URI 
    console.log(imageURI); 

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

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

    // Show the captured photo 
    // The inline CSS rules are used to resize the image 
    largeImage.src = imageURI; 
} 
// Called if something bad happens. 
function onFail(message) {alert('Failed because: ' + message); 
} 





// put in index.html <img style="display:none;" id="largeImage" src="" /> 
+0

不錯的一個...謝謝 – Mrunal 2013-04-02 16:22:46