• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to cache images
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to cache images


  • Subject: Re: how to cache images
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 08 Jun 2013 10:01:26 -0500

On Jun 8, 2013, at 4:25 AM, Gerriet M. Denkmann wrote:

> 	NSImage *image = [ [ NSImage alloc ] initByReferencingURL: url ];

> First I tried: [ NSArchiver archiveRootObject: image toFile: @"/tmp/anImage" ] but this archives the Url, NOT the data.

That's a documented consequence of using -initByReferencingURL:.  If you use -initWithContentsOfURL: that shouldn't happen.

Alternatively, you could force the image to load and then use +[NSBitmapImageRep representationOfImageRepsInArray:usingType:properties:] to create an NSData from the image's representations and save that to file.

Another approach would be to use NSURLConnection to obtain the image data.  That should use the URL cache by default.  If it doesn't, you can configure it to.  That way, you wouldn't have to manage the cache yourself.  (You should make sure the host isn't claiming that the image has to be reloaded every time – i.e. can't be cached.  Maybe NSImage would use the URL cache already except the host is preventing it.)

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: how to cache images
      • From: Jens Alfke <email@hidden>
References: 
 >how to cache images (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Can't set offset of a file NSOutputStream with appending enabled
  • Next by Date: Re: Can't set offset of a file NSOutputStream with appending enabled
  • Previous by thread: how to cache images
  • Next by thread: Re: how to cache images
  • Index(es):
    • Date
    • Thread