存储在手机中的图像未显示在屏幕上

时间:2013-05-02 05:42:13

标签: android titanium

使用钛中的函数为基于Android的应用程序。

StoreImage: function(args,image){
        var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,DataStorage.GetImageFileName(args));
        if(f.exists()){
            var success = f.deleteFile();
        var msg = 'DataStorage.js : StoreImage : File Exists Deleting First | ';
            Ti.API.info((success==true) ? msg + 'success' : msg + 'fail'); // outputs 'success'
        }
        f.write(image);

        return f.nativePath; 
    }

它将image_detail和图像作为参数并将图像保存到我的手机,此功能将图像保存到某处并返回原始路径,即file:///data/data/com.contingent.pcc/app_appdata/158664_584.png现在发出它我需要在屏幕上显示此图像但是

var imgView = Ti.UI.createImageView({
        image : "file:///data/data/com.contingent.pcc/app_appdata/158664_584.png",
        width : 220,
        height : 220, //(newWidth/myImage.width)*myImage.height,
        top : 0
    });

imgView不会在屏幕上显示图片,任何帮助

注意:相同的代码适用于iPhone。

提前致谢。

2 个答案:

答案 0 :(得分:1)

enter image description here

如果您的图片位于:

file:///data/data/com.contingent.pcc/app_appdata/maps.png

然后我必须这样做:

//FirstView Component Constructor
function FirstView() {
    //create object instance, a parasitic subclass of Observable
    var self = Ti.UI.createView();

    //label using localization-ready strings from <app dir>/i18n/en/strings.xml
    var label = Ti.UI.createLabel({
        color : '#000000',
        top : 10,
        text : String.format(L('welcome'), 'Titanium'),
        height : 'auto',
        width : 'auto'
    });
    self.add(label);

    var _storage = Ti.Filesystem.applicationDataDirectory;
    var file = Ti.Filesystem.getFile(_storage, '/maps.png');

    var av_image = Titanium.UI.createImageView({
        image : file, // the image for the image view
        top : 20,
        height : 'auto',
        width : 'auto'
    });

    self.add(av_image);

    //Add behavior for UI
    label.addEventListener('click', function(e) {
        //alert(e.source.text);
        //alert(sdcardDir);
    });

    return self;
}

module.exports = FirstView;

答案 1 :(得分:1)

找到问题的原因并自行修复。如果其他人遇到同样的问题,请在此处分享。

问题是:我正在使用代码

var image = event.media;
/***umair's code'**/
//var image = event.media;
Ti.API.info(image.width + ' x ' + image.height);
var imageView = Titanium.UI.createImageView({
image : image,
width : 375,
height : 500
});
image = imageView.toImage().media;
Ti.API.info(image.height + " x " + image.width);

用于调整图像大小,并且由于行image = imageView.toImage().media;文件变为空并且未显示。我只是评论了这一行

//image = imageView.toImage().media;
//Ti.API.info(image.height + " x " + image.width);.

一切都很顺利。

感谢所有帮助过我的人。

相关问题