• 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 21:08:59 -0500

On Jun 8, 2013, at 7:39 PM, Gerriet M. Denkmann wrote:

> 	url = some/picture.gif
> 	NSDataReadingOptions mask = 0;	//	NSDataReadingUncached
> 	NSData *data = [ NSData dataWithContentsOfURL: url options: mask error: &outError ];
> got 19420 bytes
>
> 	NSImage *image = [ [ NSImage alloc ] initWithContentsOfURL: url ];
> 	BOOL ok = [ NSArchiver archiveRootObject: image toFile: @"/tmp/anImage" ];
> got 307559 bytes (NSKeyedArchiver adds another half  kB)
>
> This 16-fold increase of data is - regardless of image quality - not acceptable for my purposes.

This isn't the technique I recommended.  Don't archive the image object.  Create a data representation using +[NSBitmapImageRep representationOfImageRepsInArray:usingType:properties:].

$ python
...
>>> from AppKit import *
>>> u = NSURL.URLWithString_("https://upload.wikimedia.org/wikipedia/commons/e/e2/Sunflower_as_gif_small.gif";)
>>> d1 = NSData.dataWithContentsOfURL_(u)
>>> d1.length()
57270
>>> i = NSImage.alloc().initWithContentsOfURL_(u)
>>> d2 = NSBitmapImageRep.representationOfImageRepsInArray_usingType_properties_(i.representations(), NSGIFFileType, None)
>>> d2.length()
54377

It actually got smaller!

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

References: 
 >how to cache images (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: how to cache images (From: Ken Thomases <email@hidden>)
 >Re: how to cache images (From: Jens Alfke <email@hidden>)
 >Re: how to cache images (From: Ken Thomases <email@hidden>)
 >Re: how to cache images (From: Jens Alfke <email@hidden>)
 >Re: how to cache images (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: how to cache images
  • Next by Date: Re: how to cache images
  • Previous by thread: Re: how to cache images
  • Next by thread: CALayer -displayLayer:inContext: never called during frame/bounds animation
  • Index(es):
    • Date
    • Thread