【问题标题】:File name is changed when using allowEdit in phonegap在 phonegap 中使用 allowEdit 时更改文件名
【发布时间】:2014-09-12 15:53:57
【问题描述】:

我正在使用 phonegap 创建 android 应用程序。因为我需要从 gallery 捕获图像。所以我写了以下代码来捕获图像

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 
});

它工作正常并捕获图像。

问题是在相机选项中插入 allowEdit 时,图像名称已更改。如果我删除了

/*allowEdit : true,
        targetWidth: 600,
        targetHeight: 600,*/

默认图片名称是persist。

如何编辑时避免重命名。有人帮助解决这个问题。

【问题讨论】:

  • 编辑后图像保存在哪里@Ela
  • @Sport 保存在我的 SD 卡中,例如 appname/files/myimage.jpg

标签: android cordova


【解决方案1】:

在 phonegap / cordova(version 3.3) 中使用 "allowEdit:true and target height and width" 相机选项时相机插件有一个默认名称,例如 "resize.jpg"。

所以它总是存储为 resige.jpg 并且仅用于从图库中选择图像时而不是使用相机拍摄图像时。

因此您可以更改 cameraLauncher.java 中的默认字符串(存在于 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

【讨论】:

    猜你喜欢
    • 2015-01-04
    • 1970-01-01
    • 2016-08-24
    • 2016-03-06
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 2011-02-20
    • 2023-03-09
    相关资源
    最近更新 更多