Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ImageToDataTransformer.m
- // ProfitTrain
- //
- // Created by Michael Zornek on 10/4/11.
- // Copyright (c) 2011 Clickable Bliss. All rights reserved.
- //
- #import "ImageToDataTransformer.h"
- @implementation ImageToDataTransformer
- + (BOOL)allowsReverseTransformation
- {
- return YES;
- }
- + (Class)transformedValueClass
- {
- return [NSData class];
- }
- - (id)transformedValue:(id)value
- {
- // IMP1
- //NSData *bitmapData = [NSBitmapImageRep representationOfImageRepsInArray:[value representations] usingType:NSPNGFileType properties:nil];
- //return bitmapData;
- // ERROR:
- // ImageIO: <ERROR> CGImageDestinationFinalize image destination does not have enough images
- // 2011-10-05 11:53:40.694 ProfitTrain[35424:507] CGImageDestinationFinalize failed for output type 'public.png'
- // IMP2
- //NSBitmapImageRep *rep = [[value representations] objectAtIndex:0];
- //NSData *data = [rep representationUsingType:NSPNGFileType properties:nil];
- //return data;
- // ERROR: rep is not a NSBitmapImageRep it's a NSCoreUIImageRep, unrecognized selector sent to instance 0x10066cd30
- // IMP3
- //NSImage *image = (NSImage *)value;
- //return [NSKeyedArchiver archivedDataWithRootObject:image];
- // IMP3 works when working with NSImages built from files or NamedImages but failes with images returned from IKPictureTaker. When decoding these images we get:
- // 2011-10-05 12:11:42.246 ProfitTrain[35896:507] Warning - attempting to decode NSCGSImageRep
- // 2011-10-05 12:12:04.586 ProfitTrain[35896:507] *** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
- // IMP4 -- can't work since UIImagePNGRepresentation isn't available on Mac
- //NSImage *image = (NSImage *)value;
- //NSData *data = UIImagePNGRepresentation(image);
- //return data;
- // IMP5 - works but when I make a TIFFRepresentation from an NSImage I made with [NSImage imageNamed:NSImageNameUser] it looks like ass.
- NSImage *image = (NSImage *)value;
- return [image TIFFRepresentationUsingCompression:NSTIFFCompressionNone factor:0.0];
- }
- - (id)reverseTransformedValue:(id)value
- {
- NSImage *image = [[NSImage alloc] initWithData:value];
- return image;
- // IMP3 ONLY
- //return [NSKeyedUnarchiver unarchiveObjectWithData:value];
- }
- @end
Add Comment
Please, Sign In to add comment