【问题标题】:How to display image in the simulator?如何在模拟器中显示图像?
【发布时间】:2011-10-04 20:36:05
【问题描述】:

我正在使用 sqlite 数据库,并且我已将图像的路径存储在我的 sqlite 文件中。 但现在我想显示存储在 sqlite 文件中的路径中的图像。 为此,我编写了以下代码。

image_wine.image=[[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[wineDetail objectForKey:@"wine_photo1"]]];

其中 image_wine 是我的 UIImageView 和 wine_photo1 是我存储路径的 sqlite 数据库字段。

但是当我运行应用程序时,我无法在我的模拟器上获取图像。 请告诉我如何解决这个问题。

谢谢。

【问题讨论】:

    标签: iphone xcode sqlite


    【解决方案1】:

    你犯了一个非常基本的错误。您应该将 UIImage 实例分配给 UIImage 对象,而不是 UIImageView 实例。

    image_wine.image = [UIImage imageWithContentsOfFile:[wineDetail objectForKey:@"wine_photo1"] ];
    

    【讨论】:

      【解决方案2】:
      image_wine.image=[[[UIImage alloc] initWithContentsOfFile:[wineDetail objectForKey:@"wine_photo1"]] autorelease];
      

      mage_wine.image=[UIImage imageWithContentsOfFile:[wineDetail objectForKey:@"wine_photo1"]];
      

      【讨论】:

      • 您正在泄漏分配的图像,请在图像中添加autorelease
      【解决方案3】:

      在 UIImageView 中,适当的图像由 UIImage 表示。 Apple Doc

      BTW [wineDetail objectForKey:@"wine_photo1"] 是路径吗?如果图像包含在您的项目中,您应该使用 imageNamed:

      【讨论】:

        猜你喜欢
        • 2014-03-22
        • 2013-08-23
        • 2021-04-23
        • 1970-01-01
        • 2021-02-28
        • 1970-01-01
        • 2018-08-17
        • 1970-01-01
        • 2012-06-24
        相关资源
        最近更新 更多