Hey I'm having some trouble with getting the PNG representation of an NSImage object.
Here's what I'm doing:
var imgData: NSData! = coverImgView.image!.TIFFRepresentation!
var bitmap: NSBitmapImageRep! = NSBitmapImageRep(data: imgData!)
var pngCoverImage = bitmap!.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: nil)
coverImgView is an NSImageView object
However, I cannot even get it compiled somehow.
It says: Type '[NSObject: AnyObject]' does not conform to protocol 'NilLiteralConvertible' (the third line of the code I post above, argument "properties: nil")
I'm trying to do something similar to the function "PNGRepresentationOfImage" here https://gist.github.com/mtabini/1178403
Any ideas ?
Thanks a lot~
The documentation says:
func representationUsingType(_ storageType: NSBitmapImageFileType,
properties properties: [NSObject : AnyObject]) -> NSData?
So it expects a dictionary, not a nil value. Supply an empty dict like this:
var pngCoverImage = bitmap!.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:])
Only if an Optional is specified (that is it where [NSObject : AnyObject]?)
you could pass a nil value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With