【问题标题】:Cropping an image natively in phonegap with allowEdit flag使用 allowEdit 标志在 phonegap 中本地裁剪图像
【发布时间】:2015-01-04 04:09:11
【问题描述】:

我正在使用以下

phonegap 3.6.0-0.21.18
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>

我需要在 phonegap 中将图像本地裁剪为宽度:650 像素和高度:250 像素的固定尺寸。我用来实现它的调用如下所示。出于某种原因,当目标类型为 DATA_URL 时,phonegap 认为不需要使用相机启动裁剪工具。

navigator.camera.getPicture(onPhotoDataSuccess, onFail, { 
quality: 45, 
allowEdit: true, <-- Forces the crop tool to appear if target sizes are different
targetWidth: 650,
targetHeight: 250,
destinationType: destinationType.DATA_URL, <--- Changed this to work
sourceType : Camera.PictureSourceType.CAMERA, 
correctOrientation: true
});

但是当我用相机更改destinationType:destinationType.FILE_URI 时,裁剪工具会在照片拍摄后打开以进行裁剪。

当我用画廊和相同的参数尝试它时,会出现裁剪工具

navigator.camera.getPicture(onPhotoURISuccess, onFail, { 
quality: 45, 
allowEdit: true, <-- Forces the crop tool to appear if target sizes are different
targetWidth: 650,
targetHeight: 250,
destinationType: destinationType.DATA_URL,  <-- Didnt have to change for the crop tool to open
sourceType: pictureSource.SAVEDPHOTOALBUM, 
mediaType : Camera.MediaType.PICTURE,
correctOrientation: true
});

我不明白相机和图库调用之间的区别。两个代码都使用目标类型作为destinationType.DATA_URL。对于相机,裁剪工具不会打开,而对于图库,它会打开。这是android或phonegap中的一些错误吗?

【问题讨论】:

    标签: android cordova android-camera phonegap-plugins cordova-3


    【解决方案1】:

    我认为是 javascript 中的性能问题。我没有尝试原生裁剪图像,但在 iOS 中存在内存问题。我捕获了 base64 字符串 (DATA_URL) 并使用 javascript 插件对其进行了编辑。我想你也需要 base64 图像。否则,FILE_URI 更好。

    看看John Wargo's answer,也许对你有帮助

    还有这个科尔多瓦文档:

    注意:较新设备上的照片分辨率非常好。选择的照片 来自设备的画廊不会缩小到较低的质量,即使 如果指定了质量参数。为了避免常见的内存问题, 将 Camera.destinationType 设置为 FILE_URI 而不是 DATA_URL。

    【讨论】:

      猜你喜欢
      • 2017-09-22
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 2021-09-01
      相关资源
      最近更新 更多