• 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: Using NSValueTransformer to convert NSImage to NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSValueTransformer to convert NSImage to NSData


  • Subject: Re: Using NSValueTransformer to convert NSImage to NSData
  • From: Peter Zegelin <email@hidden>
  • Date: Wed, 25 Mar 2009 09:54:07 +1100


On 25/03/2009, at 1:18 AM, I. Savant wrote:

On Tue, Mar 24, 2009 at 8:39 AM, Peter Zegelin
<email@hidden> wrote:

[value description] gives just a string <................> with
nothing obvious in it.

This is basic Cocoa 101:

I know. I was expecting the class description to show something like "NSImage" or "NSData", not <4d4d002a 000009a2 80002050 3824160d.....>



http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html

 Also look at the -description method here:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html


So how do I  transform whatever value is into an NSData object for
archiving?

You haven't mentioned whether you've read this:

http://developer.apple.com/documentation/Cocoa/Conceptual/ValueTransformers/ValueTransformers.html

I have read all these but still not quite getting it.


 Essentially, you should already know what kinds of objects to
expect, what to convert, and what to ignore. If you expect to receive
more than one type (and you shouldn't with an NSImageView, since it
won't let you insert anything other than an NSImage or nil), then you
can ask it for its -class or -className to figure out what it is and
what to do with it.

 In your case, you should probably only be checking for nil (and
returning nil or the [NSNull null] placeholder in kind) or, if it's an
image, archive it and return the NSData object, or vice-versa
(depending on which direction is "reverse" for you).

 Since you haven't provided a full code listing, I can't tell if
you're missing anything else.

--
I.S.

My email had all that I have written so far ( except for trying various ways to found out what 'value' actually was). The NSImageView is bound to shared defaults and the value transformer is my ImageScalingAndArchivingTransformer class. I was expecting that if my ImageScalingAndArchivingTransformer class was:


	+ (Class)transformedValueClass { return [NSData class]; }

I would get an NSData object in one direction and an NSImage in the other, and vice versa for a

	+ (Class)transformedValueClass { return [NSImage class]; }

but either type calls reverseTransformedValue when I drop an image onto the NSImageView. If the transformedValueClass is an NSData class then:

	if ( [value isKindOfClass:[NSData class]] ) returns true

but if the transformedValueClass is NSImage

if ( [value isKindOfClass:[NSImage class]] ) returns false: it is still an NSData

so in neither case do I get an NSImage. I have since discovered that the className returns in both cases is NSConcreteData. This type doesn't seem to even appear in the documentation, so I'm not sure how to get an NSImage from it.


So I'm stumped!


regards,

Peter





_______________________________________________

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: 
 >Using NSValueTransformer to convert NSImage to NSData (From: Peter Zegelin <email@hidden>)
 >Re: Using NSValueTransformer to convert NSImage to NSData (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: [Q] Convert PixMapHandle to NSBitmapImageRep
  • Next by Date: Re: De-Mystifying NSCell
  • Previous by thread: Re: Using NSValueTransformer to convert NSImage to NSData
  • Next by thread: Class gets EXC_BAD_ACCESS only as NSOperation
  • Index(es):
    • Date
    • Thread