我目前正在创建使用Phonegap (Cordova) camera plugin的移动应用 . 它正确捕获图像并将其显示在我想要的位置,但我似乎无法设置targetWidth和targetHeight选项,如上所述 .
targetWidth:用于缩放图像的宽度(以像素为单位) . 必须与targetHeight一起使用 . 纵横比保持不变 . (Number)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
});
},
这些尝试都没有按照我的意愿取得成功;捕获图像的固定宽度和高度 .
如何在此图像上设置图像宽度和高度?
3 回答
我使用以下,它运作良好 .
它也可以根据自己的需要修改 plugin native code . 如果你正在尝试Android . 这是修复 .
在 execute 函数内,两个参数默认设置为零,表示设备捕获的完整大小,否则如果某些值通过 args 参数传递则会考虑这些参数 .
见:https://github.com/apache/cordova-plugin-camera/blob/master/src/android/CameraLauncher.java#L115
如果可能的话,你可以在本机代码中设置它并且工作正常 .
试试这个我的朋友 . 删除
allowEdit : true
如何在捕获图像后改变主意以调整图像大小?
Useful article for resizing image with HTML5 Canvas