【问题标题】:How to get Image from its native path?如何从其本机路径获取图像?
【发布时间】:2023-03-10 16:44:01
【问题描述】:

我已将图像文件的本机路径存储到数据库。现在我需要显示该图像。为此,我正在使用

imageView.image = Titanium.Filesystem.getfile(rows.fieldByName('path'));

但是没有效果。 它给出了错误

[ERROR] invalid image type. expected either TiBlob or TiFile, was: NSNull in -[TiUIImageView setImage_:] (TiUIImageView.m:679)

请提出建议。

【问题讨论】:

  • 设置 path.extension 扩展名是你使用的任何东西 ex:png,jpg 等
  • 警告路径,看看它是否正确。并且,硬编码那个 db 路径,看看它是否有效。

标签: iphone image file titanium


【解决方案1】:

我会说这是因为您返回的数据库值是一个字符串,而不是实际的图像。不像为网络指定图像路径那样工作。试试这个:

var img_src = Ti.Filesystem.getFile(rows.fieldByName('path'));
var img = img_src.read();
imageView.image = img;

【讨论】:

    【解决方案2】:

    你可以在图片属性中给出原生路径

    var u_image = Titanium.UI.createImageView({ image: rows.fieldByName('path'), top:10, left:10, height:20, width:20 });

    这可能对你有帮助!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-13
      • 2015-12-25
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      相关资源
      最近更新 更多