uiimagepngrepresentation

NSImage to NSData as PNG Swift

谁都会走 提交于 2019-11-28 13:18:58
I am writing a Mac app based on an iOS app. The code below converts a UIImage to NSData to upload to Parse.com. I would like to do the same for Mac but I do not seem to be able to convert it to NSData. What should I be doing? Thanks var image = UIImage(named: "SmudgeInc") let imageData = UIImagePNGRepresentation(image) let imageFile = PFFile(name:"image.png", data:imageData) You can use the NSImage property TIFFRepresentation to convert your NSImage to NSData : let myImageData = yourImage.TIFFRepresentation! If you need to save your image data to a PNG file you can use NSBitmapImageRep(data:)

NSImage to NSData as PNG Swift

笑着哭i 提交于 2019-11-27 07:36:10
问题 I am writing a Mac app based on an iOS app. The code below converts a UIImage to NSData to upload to Parse.com. I would like to do the same for Mac but I do not seem to be able to convert it to NSData. What should I be doing? Thanks var image = UIImage(named: "SmudgeInc") let imageData = UIImagePNGRepresentation(image) let imageFile = PFFile(name:"image.png", data:imageData) 回答1: You can use the NSImage property TIFFRepresentation to convert your NSImage to NSData : let imageData = yourImage

UIImagePNGRepresentation issues? / Images rotated by 90 degrees

落爺英雄遲暮 提交于 2019-11-27 00:21:37
I want to load images from UIImagePickerController, then save the selected photo to my app's document directory. UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; NSData *data1 = UIImagePNGRepresentation(image); NSString *fileName = "1.png"; NSString *path = //get Document path, then add fileName BOOL succ = [data1 writeToFile:path atomically:YES]; but after I save the image to my document, I found that, the image was rotated 90 degree, then I change the method UIImagePNGRepresentation to UIImageJPEGRepresentation, this time it's fine, anyone know what's the problem? I

PNG/JPEG representation from CIImage always returns nil

左心房为你撑大大i 提交于 2019-11-26 17:59:21
I'm currently making a photo editing app. When a photo is selected by the user, it is automatically converted into black and white using this code: func blackWhiteImage(image: UIImage) -> Data { print("Starting black & white") let orgImg = CIImage(image: image) let bnwImg = orgImg?.applyingFilter("CIColorControls", withInputParameters: [kCIInputSaturationKey:0.0]) let outputImage = UIImage(ciImage: bnwImg!) print("Black & white complete") return UIImagePNGRepresentation(outputImage)! } The problem I am having with this code is that I keep getting this error: fatal error: unexpectedly found nil