2014-11-24 94 views
14

我目前正在創建使用Phonegap (Cordova) camera plugin的移動應用程序的過程。它正確捕獲圖像並將其顯示在我想要的位置,但我似乎無法設置targetWidth和targetHeight選項,如上所述。設置相機的寬度和高度phonegap相機

targetWidth:以像素爲單位的縮放圖像的寬度。必須與 targetHeight一起使用。長寬比保持不變。 (數量)

targetHeight:以像素爲單位的高度來縮放圖像。必須與 targetWidth一起使用。長寬比保持不變。 (數量)

據我所知,這將改變輸出圖像的寬度和高度。但是,他們似乎沒有工作。

建議我在研究解決方案時發現,使用可選參數allowEdit。在這我可以讓用戶選擇一個預先設置的平方圖像。但是,這似乎也不起作用。

查看我的代碼以供參考。

camera: function() { 
    //Fire up the camera! 
    navigator.camera.getPicture(onSuccess, onFail, { 
     destinationType: Camera.DestinationType.DATA_URL, 
     allowEdit: true, 
     targetWidth: 512, 
     targetHeight: 512 
    }); 
}, 

無論是attemps的成功是我想要的;拍攝圖像的固定寬度和高度。

如何在此圖像上設置圖像寬度和高度?

回答

0

我用以下,而且運作良好。

{ 
    quality: 25, 
    targetWidth: 500, 
    targetHeight: 500, 
    destinationType: Camera.DestinationType.FILE_URI, 
    sourceType: Camera.PictureSourceType.CAMERA, 
    correctOrientation: true 
} 

它也可以修改插件機代碼按照自己的需要。如果你正在嘗試使用android。這是修復。

內部執行函數,這兩個參數是默認爲零,這意味着由設備捕獲的全尺寸設置;否則,如果某些值由ARGS傳遞然後參數那些被考慮在內。

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 

      this.callbackContext = callbackContext; 

    if (action.equals("takePicture")) { 
       int srcType = CAMERA; 
       int destType = FILE_URI; 
       this.saveToPhotoAlbum = false; 
       this.targetHeight = 0; 
       this.targetWidth = 0; 
       this.encodingType = JPEG; 
       this.mediaType = PICTURE; 
       this.mQuality = 80; 

       this.mQuality = args.getInt(0); 
       destType = args.getInt(1); 
       srcType = args.getInt(2); 
       this.targetWidth = args.getInt(3); 
       this.targetHeight = args.getInt(4); 
       this.encodingType = args.getInt(5); 
       this.mediaType = args.getInt(6); 
       this.allowEdit = args.getBoolean(7); 
       this.correctOrientation = args.getBoolean(8); 
       this.saveToPhotoAlbum = args.getBoolean(9); 

見:https://github.com/apache/cordova-plugin-camera/blob/master/src/android/CameraLauncher.java#L115

如果可能的話,你可以將其設置以及在本地代碼和正常工作。

3

試試這個我的朋友。刪除allowEdit : true

camera: function() { 
     navigator.camera.getPicture(onSuccess, onFail, { 
      quality: 50, 
      targetWidth: 512, 
      targetHeight: 512, 
      destinationType: navigator.camera.DestinationType. DATA_URL, 
      saveToPhotoAlbum: true, 
      correctOrientation: true 
     }); 
    } 
相關問題