问题描述:

I was using this code for save a pic after I scaled it:

NSData *dataToWrite = [rep representationUsingType:NSPNGFileType properties:nil];

[dataToWrite writeToFile:finalPath atomically:NO];

and it was working fine, but now with new Xcode I get a warning:

Null passed to a callee that requires a non-null argument

What should I put in properties instead of nil?

Thanks a lot for any help

网友答案:

You need to pass an NSDictionary, with the possible keys to the dictionary being found in NSBitmapImageRep.h (You can pass in an empty dictionary, though)

APPKIT_EXTERN NSString* NSImageCompressionMethod;   // TIFF input/output (NSTIFFCompression in NSNumber)
APPKIT_EXTERN NSString* NSImageCompressionFactor;   // TIFF/JPEG input/output (float in NSNumber)
APPKIT_EXTERN NSString* NSImageDitherTransparency;  // GIF output (BOOL in NSNumber)
APPKIT_EXTERN NSString* NSImageRGBColorTable;       // GIF input/output (packed RGB in NSData)
APPKIT_EXTERN NSString* NSImageInterlaced;      // PNG output (BOOL in NSNumber)
APPKIT_EXTERN NSString* NSImageColorSyncProfileData;    // TIFF,GIF input/output (NSData)
APPKIT_EXTERN NSString* NSImageFrameCount;  // GIF input (int in NSNumber) (read-only)
APPKIT_EXTERN NSString* NSImageCurrentFrame;    // GIF input (int in NSNumber)
APPKIT_EXTERN NSString* NSImageCurrentFrameDuration;    // GIF input (float in NSNumber) (read-only)
APPKIT_EXTERN NSString* NSImageLoopCount            ;   // GIF input (int in NSNumber) (read-only)
APPKIT_EXTERN NSString* NSImageGamma                ;   // PNG input/output (float in NSNumber)
APPKIT_EXTERN NSString* NSImageProgressive          ;   // JPEG input/output (BOOL in NSNumber)
APPKIT_EXTERN NSString* NSImageEXIFData             ;   // JPEG input/output (NSDictionary)
APPKIT_EXTERN NSString* NSImageFallbackBackgroundColor  NS_AVAILABLE_MAC(10_5); // JPEG output (NSColor)
网友答案:

For anyone having the same problem I resolved creating this NSDictionary:

NSDictionary * dict = [NSDictionary dictionaryWithObject: [NSNumber numberWithFloat:0.5] forKey:NSImageCompressionFactor];

and putting "dict" instead of nil in properties.

相关阅读:
Top