-1

this issue has troubled me for some time。i should allow user to scale image,so i choose svg instend of jpg/png ,one of question is that i hava to store svg because such svg resource are loaded form netWork,but i find that if i archiver svg into data,read data from disk transform to svg,it cost some time to render svg。so i change other method ,i want to archiver JAMSVGImage instance ,but what i stuck in is that i can't find any way to archiver JAMSVGImage。now i just cache JAMSVGImage into memory with singleton,but as we all know,every time when the app has killed or stop running background ,we lost the cache data in singleton,who can help me to slove this issus,thanks!

JerryLee
  • 3
  • 3

1 Answers1

1

What you probably want to do is store the SVG, render it to a new UIImage (using JAMSVGImage's imageAtSize: method), and store a PNG representation of that UIImage in your application's cache directory.

When you application starts, you check whether the corresponding PNG in the cache directory exists and load that instead of the SVG. You would then only load the SVG when you really need it, for example when resizing.

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • thanks very much for @DarkDust tips,it's very helpfull to me! – JerryLee Aug 31 '15 at 08:06
  • Addtion: i have sloved this issue by this way. First, i download svg(XML) via a url with [NSData dataWithUrl:url] ,after this sychronous request finished,i cache this receive data to disk with url MD5.Then next time,if i need display this svg,First i judge local disk whether exist NSData with url MD5,Second,if return data's length is not zero, use it,Otherwise,dowlond it。 – JerryLee Jun 21 '16 at 02:39