daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Jan 14th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  ImageToDataTransformer.m
  3. //  ProfitTrain
  4. //
  5. //  Created by Michael Zornek on 10/4/11.
  6. //  Copyright (c) 2011 Clickable Bliss. All rights reserved.
  7. //
  8.  
  9. #import "ImageToDataTransformer.h"
  10.  
  11. @implementation ImageToDataTransformer
  12.  
  13. + (BOOL)allowsReverseTransformation
  14. {
  15.     return YES;
  16. }
  17.  
  18. + (Class)transformedValueClass
  19. {
  20.     return [NSData class];
  21. }
  22.  
  23. - (id)transformedValue:(id)value
  24. {
  25.     // IMP1
  26.     //NSData *bitmapData = [NSBitmapImageRep representationOfImageRepsInArray:[value representations] usingType:NSPNGFileType properties:nil];
  27.     //return bitmapData;
  28.     // ERROR:
  29.     // ImageIO: <ERROR>  CGImageDestinationFinalize image destination does not have enough images
  30.     // 2011-10-05 11:53:40.694 ProfitTrain[35424:507] CGImageDestinationFinalize failed for output type 'public.png'
  31.    
  32.     // IMP2
  33.     //NSBitmapImageRep *rep = [[value representations] objectAtIndex:0];
  34.     //NSData *data = [rep representationUsingType:NSPNGFileType properties:nil];
  35.     //return data;
  36.     // ERROR: rep is not a NSBitmapImageRep it's a NSCoreUIImageRep, unrecognized selector sent to instance 0x10066cd30
  37.    
  38.     // IMP3
  39.     //NSImage *image = (NSImage *)value;
  40.     //return [NSKeyedArchiver archivedDataWithRootObject:image];
  41.     // IMP3 works when working with NSImages built from files or NamedImages but failes with images returned from IKPictureTaker. When decoding these images we get:
  42.     // 2011-10-05 12:11:42.246 ProfitTrain[35896:507] Warning - attempting to decode NSCGSImageRep
  43.     // 2011-10-05 12:12:04.586 ProfitTrain[35896:507] *** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
  44.    
  45.     // IMP4 -- can't work since UIImagePNGRepresentation isn't available on Mac
  46.     //NSImage *image = (NSImage *)value;
  47.     //NSData *data = UIImagePNGRepresentation(image);
  48.     //return data;
  49.    
  50.     // IMP5 - works but when I make a TIFFRepresentation from an NSImage I made with [NSImage imageNamed:NSImageNameUser] it looks like ass.
  51.     NSImage *image = (NSImage *)value;
  52.     return [image TIFFRepresentationUsingCompression:NSTIFFCompressionNone factor:0.0];
  53. }
  54.  
  55. - (id)reverseTransformedValue:(id)value
  56. {
  57.     NSImage *image = [[NSImage alloc] initWithData:value];
  58.     return image;
  59.    
  60.     // IMP3 ONLY
  61.     //return [NSKeyedUnarchiver unarchiveObjectWithData:value];
  62. }
  63.  
  64. @end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top