文件名中的PhoneGap使用allowEdit改变时, [英] File name is changed when using allowEdit in phonegap
问题描述
我使用PhoneGap的创建android应用。在我需要从图库捕捉图像。所以我写了下面的code捕捉图像
I am using phonegap to create android application. In that i need to capture the image from gallery . So i wrote the following code for capturing image
navigator.camera.getPicture(function(imageURI){
window.resolveLocalFileSystemURI(imageURI, function(fileEntry){
fileEntry.file(function(fileObj) {
console.log(fileObj.name);
});
}, fail);
}, fail, { quality: 100, allowEdit : true,
targetWidth: 600,
targetHeight: 600,
destinationType: destinationType.NATIVE_URI,
sourceType: pictureSource.PHOTOLIBRARY
});
这是工作的罚款,并拍摄照片。
It is working fine and capture the image.
问题是,当插入 allowEdit 在相机选项映像名称是changed.If我删除
The problem is when insert allowEdit in camera options the image name is changed.If i remove the
/*allowEdit : true,
targetWidth: 600,
targetHeight: 600,*/
默认映像名称是坚持。
default image name is persist.
如何避免重命名编辑的时候。有人有助于摆脱这一问题。
How to avoid the rename when editing. Someone help to get out this problem.
推荐答案
在 的PhoneGap /科尔多瓦(3.3版本)的使用时allowEdit:true和目标高度和宽度作为相机选项相机插件有例如默认名称resize.jpg。
In phonegap / cordova(version 3.3) when using "allowtrue and target height and width" for camera options the camera plugin has a default name like "resize.jpg".
所以它总是存储为 resige.jpg 并且也仅仅是从画廊的当挑图片时,将影像不使用摄像头。
So it always stored as resige.jpg and also it is only for when pick image from gallery not when take image using camera .
所以,你可以更改默认的字符串 cameraLauncher.java (SRC / org.apache.cordova.camera内present)
So you can change the default string in cameraLauncher.java (present inside src/org.apache.cordova.camera)
取而代之的是
// Create an ExifHelper to save the exif data that is lost during compression
String resizePath = getTempDirectoryPath() + "/resize.jpg";
// Some content: URIs do not map to file paths (e.g. picasa).
String realPath = FileHelper.getRealPath(uri, this.cordova);
替换该
String realPath = FileHelper.getRealPath(uri, this.cordova);
int postition = realPath.lastIndexOf( '.' );
// your image format like jpg or png
String imageFormat = realPath.substring(postition+1);
// your image name
String imageName = realPath.substring(0,postition);
//now the default name is changed
String resizePath = getTempDirectoryPath() + "/"+imageName+"."+imageFormat;
注意* 这个答案是仅适用于Android
NOTE * This answer is only for android
这篇关于文件名中的PhoneGap使用allowEdit改变时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!