2014-11-24 57 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 
     }); 
    }