문제

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 ?

도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top