Monotouch序列化UIImage

时间:2010-05-09 12:08:13

标签: c# serialization xamarin.ios

我需要在本地缓存图像,并考虑将它们保存为SerializableDictionary

SerializableDictionary来自:http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx

我想知道这是不是

a:处理图像缓存的好方法(对于离线模式 - 数据会不断更新,因此首先从网络中提取)。

b:我怎么能这样做?

我似乎只剩下以下xml:

    <?xml version="1.0" encoding="us-ascii"?>
<dictionary>
  <item>
    <key>
      <string>http://img.theguidestar.com/thumb/491520.png</string>
    </key>
    <value>
      <UIImage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <Handle />
        <Size>
          <Width>0</Width>
          <Height>0</Height>
        </Size>
      </UIImage>
    </value>
  </item>
</dictionary>

我应该做些什么来使它自己序列化图像?

瓦特://

1 个答案:

答案 0 :(得分:0)

UIImage和CGIMage不允许轻松访问其数据。因此,在XML文档中序列化图像非常困难。

您可以使用以下解决方案:

  • 从网络中检索图像并将其存储在用户的文档文件夹中。
  • 将图像的网址映射到字典中图像的本地路径。
  • 使用Dictionary作为缓存索引来访问图像。