Frage

I am storing OSX icons (NSImage) in core data as Transformable attributes. IOS is unable to decode the NSImage it seems.

What are my options for storing a compatible image in Core Data, using a transformable (or other) attribute and accessing the image on iOS.

Currently the user can drop their own image onto the NSImageWell and this is stored in the objective-c class as an NSImage. This obviously gets archived into the core data transformable and when iOS tried to retrieve it it throws an exception because it does not understand an NSImage object.

Is there something other than NSImage I can use on OS X that will be compatible with iOS ?

War es hilfreich?

Lösung

PNG (= Portable Network Graphics) is an option.

You can convert an NSImage to PNG data with (copied from How to save a NSImage as a new file):

NSImage *image = ...;
NSBitmapImageRep *imgRep = [[image representations] objectAtIndex: 0];
NSData *pngData = [imgRep representationUsingType: NSPNGFileType properties: nil];

and create an UIImage from PNG data with

UIImage *image = [UIImage imageWithData:pngData];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top