Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift iOS'的等价物是什么;OS X的UIImagePNGRepresentation()?_Swift_Macos_Cocoa_Uiimagepngrepresentation - Fatal编程技术网

Swift iOS'的等价物是什么;OS X的UIImagePNGRepresentation()?

Swift iOS'的等价物是什么;OS X的UIImagePNGRepresentation()?,swift,macos,cocoa,uiimagepngrepresentation,Swift,Macos,Cocoa,Uiimagepngrepresentation,我正在尝试使用Swift从OS X向Parse.com上传一个图像文件。搜索Parse.com文档(针对OS X)时,我发现以下代码: let imageData = UIImagePNGRepresentation(image) let imageFile = PFFile(name:"image.png", data:imageData) var userPhoto = PFObject(className:"UserPhoto") userPhoto["imageName"] = "My

我正在尝试使用Swift从OS X向Parse.com上传一个图像文件。搜索Parse.com文档(针对OS X)时,我发现以下代码:

let imageData = UIImagePNGRepresentation(image)
let imageFile = PFFile(name:"image.png", data:imageData)

var userPhoto = PFObject(className:"UserPhoto")
userPhoto["imageName"] = "My trip to Hawaii!"
userPhoto["imageFile"] = imageFile
userPhoto.saveInBackground()
问题在于它使用的是UIImagePNGRepresentation(),它来自iOS API,而不是OS X


有人知道如何在OS X和Swift上正确执行此操作吗?

UIImagePNGRepresentation
类似的功能可能是:

let cgImgRef = image.CGImageForProposedRect(nil, context: nil, hints: nil)
let bmpImgRef = NSBitmapImageRep(CGImage: cgImgRef!)
let pngData = bmpImgRef.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:])

// your code bellow

let imageFile = PFFile(name:"image.png", pngData)

var userPhoto = PFObject(className:"UserPhoto")
userPhoto["imageName"] = "My trip to Hawaii!"
userPhoto["imageFile"] = imageFile
userPhoto.saveInBackground()

试试这个,告诉我们它是否有效:1)什么是图像?2) 什么是
PFFile
PFObject
?它们不存在于apple文档中,所以它们是第三方库。如果你提到它们,那么你还应该指定在哪里找到它们,这是pngData行。我只在Plinio提供的代码中插入该行。你读过问题代码了吗?