Swift – Create PNG or JPG from UIImage (not for saving locally)

jpegpngswiftswift2uiimage

How to create a png or jpg file from a UIImage (camera/gallery), my aim isn't for saving locally I should upload this image as image to server.

tried UIImageJPEGRepresentation and UIImagePNGRepresentation but they both creates a NSData, I want pure png/swift files-images.

Best Answer

For me, I'll encode the image and send the encoded string to server, then only convert it back and save it as whatever format you like.

You can refer "this link" to know more about encoding the image.

Related Topic