Re: Core Data, NSImageView, and Thumbnailing
Re: Core Data, NSImageView, and Thumbnailing
- Subject: Re: Core Data, NSImageView, and Thumbnailing
- From: Chris Hanson <email@hidden>
- Date: Fri, 25 Aug 2006 15:52:30 -0700
On Aug 25, 2006, at 2:43 PM, David Rocamora wrote:
I'm writing a simple CoreData application and I have created an
NSImageView
that is editable so that users can drag pictures onto to select an
image for
each record. This is working great.
My problem is that I'm really only interested in saving the
thumbnails of
the pictures and the way it's working now it saves the entire
image. This
gets out of hand when a user selects a large picture. How would I
go about
making a thumbnail of the image as soon as it's dragged onto the
NSImageView??
"How do I generate a thumbnail from an image?" really isn't a Core
Data question; the fact that you're using Core Data isn't really
relevant to it. However, there is a Core Data question lurking in
the above once you figure out how to generate a thumbnail: How do
you manage both an "image" attribute and a "thumbnail" attribute
where the thumbnail is the only one you want to save?
That has a fairly straightforward answer. Your image attribute
should be marked transient in your data model. Either when your
image is set, or when your managed object instance is saved, you
should generate a thumbnail from the image and assign it to the
thumbnail attribute. And either when your image is accessed, or when
your managed object instance is awakened from a fetch, you should
return your thumbnail data instead.
What you're really doing here is using the thumbnail persistent
attribute as a backing store for the image transient attribute. How
to follow this pattern in the general case is described in the Core
Data documentation; this is just a specific case. Other similar
cases might be to have an NSURL as an attribute or an attribute
representing a reference to a file.[1]
Another interface-centric possibility -- which may be a lot easier,
depending on your needs -- might be to write your own value
transformer to apply to the NSImageView's data binding. When
transforming from the image view's NSImage to an NSData, your value
transformer could also turn the image into a thumbnail if it's too
large.
-- Chris
[1] Both of these would be represented in your model as a transient
attribute with an undefined attribute type. A URL attribute would be
backed by a persistent string attribute containing the text of the
URL, since there's no "URL" attribute type. A file reference
attribute would be backed by either a persistent string attribute
containing the text of a path/URL or a persistent binary data
attribute containing an alias record, since there's no "file
reference" attribute type.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden