2012-10-03 25 views
6

我只能在其文檔中找到有關用於返回設備方向的加速度計的信息。無論如何,電話可以返回拍攝照片時設備被佔用的方式? 要使用相機時,我這樣做:圖像捕獲期間Phonegap返回當前方向

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

當成功返回時,它這樣做。

function onPhotoDataSuccess(imageData) { 
     var baseImg = imageData; 
     $('#uploadPreUpImgSwapHtml').html('<img src="data:image/jpeg;base64,'+ baseImg +'" style="max-width:100%; width:auto; max-height:300px; height:auto;"/>'); 
     $('#uploadPreBaseDataSwapHtml').html('<input type="hidden" id="chosenPictureData" value="'+ baseImg +'" />'); 
     $('#uploadPictureBtnHideHtml').fadeIn(); 

    } 

是否有一個回調,返回裝置正在舉行什麼樣的方式,而照片的拍攝,所以我可以把它送到我的上傳文件,並正確地旋轉圖片的成功?

回答

23

爲了使您的生活更輕鬆,你可以叫:

navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, 
    destinationType: destinationType.FILE_URI, 
    correctOrientation: true }); 

,那麼你會得到正確旋轉的文件。

+2

哦哇!這工作出色!非常感謝!我沒有看到在文件中,當我搜索答案,並發現這個http://stackoverflow.com/questions/9902797/phone-gap-camera-orientation他們說,發生的唯一原因是因爲我是使用base64並且該數據不會與base64一起傳遞。 – user1053263

+0

非常感謝!這解決了我在三星設備上的問題,我總是在橫向上獲得圖像(雖然設備處於potrait方向) – Stradivari

+0

傑出的,今晚將在我正在進行的一個項目上嘗試這個項目,我希望它能起作用! OMG !!! – Mike

相關問題