Re: Base64 encoding of NSImage
Re: Base64 encoding of NSImage
- Subject: Re: Base64 encoding of NSImage
- From: Jens Alfke <email@hidden>
- Date: Mon, 02 Jul 2012 08:53:43 -0700
On Jul 2, 2012, at 5:08 AM, Andreas Grosam wrote:
> Well, embedding an image encoded in base64 in a JSON document is not that "RESTful" anyway.
Sure it is. Plenty of REST-based APIs do this sort of thing (CouchDB and Atom both come to mind.) The REST principles don't dictate any particular transfer format for data, and allow for aggregate URLs that represent multiple resources.
> There are third party JSON libraries which are capable to customize the mapping, though. For instance, it might suffice to implement a method for a Category for NSImage to accomplish this (JPJson library uses this approach for example). That way, you can serialize a hierarchy of Foundation objects which contains a NSImage - no matter where this occurs in the tree.
It's certainly possible to do that, but it doesn't seem like a good idea to me, because there's no unambiguous data format associated with an image. Even choosing between the two most obvious formats (JPEG and PNG) involves a decision about trade-offs between fidelity loss and file size.
I would instead have the app itself decide how to encode the image as data, and then set up an unambiguous mapping from NSData to base64-encoded JSON strings. (Of course on the other end it's trickier because how does the decoder know what strings should be decoded to NSData and which should be left alone? YAML has type annotations that provide for this, but JSON doesn't.)
—Jens
_______________________________________________
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