2014-10-01 99 views
1

我做了PhoneGap的應用程序,我採取這種方法的畫面:PhoneGap的圖像質量

// A button will call this function 
// 
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, 
     targetWidth: 100 
    }); 
} 

但我想知道是否有在PhoneGap的辦法知道這是拍攝照片的重量。

回答

0

我已經看過這個,看起來PhoneGap Camera plugin不能幫你找出產生的圖像的重量。

爲了解釋發生了什麼,當你已經拍攝的照片,你可以在你的成功的功能做到這一點:

function onPhotoDataSuccess(imageData) { 
    var image = document.getElementById('myImage'); 
    image.src = "data:image/jpeg;base64," + imageData; 
} 

你有一個JavaScript Image對象結束。您可以在這裏閱讀更多Determining image file size + dimensions via Javascript?關於確定JavaScript中的圖像文件大小,不幸的是,似乎並沒有一個簡單直接的解決方案。

+0

是的,這是我用圖片做的。但同時我通過ajax發送給服務器,我需要知道圖像的重量。我試圖從服務器獲取base64圖片以在php中使用它。但是我還無法解碼照片。一旦我從PHP獲得照片,將更容易知道重量。 – cristina 2014-10-02 06:46:53

+0

所以你要求在PHP中進行大小計算?你有沒有嘗試strlen(base64_decode($ encoded_data)); ? – HischT 2014-10-02 10:47:25

+0

不,我想在發送到服務器之前知道照片的大小。 – cristina 2014-10-02 15:19:14