【问题标题】:Image from gallery gives null object in IOS for Appcelerator来自画廊的图像在 IOS 中为 Appcelerator 提供了空对象
【发布时间】:2016-05-04 07:53:56
【问题描述】:

我想从图库中获取所选图像的文件名和本机路径。以下代码适用于 Android 但在 IOS 中为 null。

Titanium.Media.openPhotoGallery({
success : function(event) {
    selectedImage = event.media;
    //Ti.API.info("image : " + JSON.stringify(selectedImage));  --> Returns {}
    if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
        //Ti.API.info("selectedImage : " + JSON.stringify(selectedImage));    --> Returns {}
        //Ti.API.info("selectedImage : " + JSON.stringify(selectedImage.nativePath));  --> Returns null
        //Ti.API.info("selectedImage.file.name : " + JSON.stringify(selectedImage.file.name));  --> Throws error
    }
}
}); 

还有其他方法可以获取fileName、ImageType和nativePath吗?

提前致谢。

【问题讨论】:

    标签: image appcelerator appcelerator-titanium photo-gallery


    【解决方案1】:

    如您所见,您无法通过 JSON 序列化 blob 来查看其所有属性。尽管有文档,但您似乎无法在 ios 上获得本机路径。

    Titanium.Media.openPhotoGallery({
        success : function(e) {
            Ti.API.info ("Got image:");
            Ti.API.info ("  width:      " + e.media.width);
            Ti.API.info ("  height:     " + e.media.height);
            Ti.API.info ("  pixels:     " + e.media.size);
            Ti.API.info ("  bytes:      " + e.media.length);
            Ti.API.info ("  mimeType:   " + e.media.mimeType);
            Ti.API.info ("  nativePath: " + e.media.nativePath);
        }
    }); 
    

    给我

    [INFO] Got image:
    [INFO]   width:      3000
    [INFO]   height:     2002
    [INFO]   pixels:     6006000
    [INFO]   bytes:      4752033
    [INFO]   mimeType:   image/jpeg
    [INFO]   nativePath: null
    

    有一个与图像 blob 关联的文件属性(它绝对不为空),但我无法访问该文件对象的任何属性。如您所见,nativePath 返回为 null。

    也就是说,您确定需要本机路径吗?我已经能够获取图像数据,对其进行下采样(使用 ImageFactory 模块),然后通过 HTTP 将其发送到服务器,而这一切都不知道本机路径。

    【讨论】:

    • nativePath(和其他一些 Blob 属性)仅在 Blob 来自磁盘上的文件时可用。对于 photoGallery,Blob 仅存在于内存中,因为您无法访问照片库中的原始文件。
    • 实际上,我想显示所选图像的图像名称,有什么方法可以获取名称吗?我想要的流程是,用户从图库中选择图像 -> 图像上传到服务器 -> 显示已在应用程序中上传的 ImageName(filename)。
    猜你喜欢
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2012-10-03
    • 2015-08-30
    相关资源
    最近更新 更多