0

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.

turushan
  • 690
  • 7
  • 25
  • 2
    NSData has what you want. PNG & JPEG data just happens to be the byte for byte representation needed for the file. Just use the getBytes method of NSData and that's the 'file' you're after. I don't think there's any other iOS methods to do what you want more easily. – BitBank Feb 21 '16 at 08:54

1 Answers1

0

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.

Community
  • 1
  • 1
Lee
  • 850
  • 11
  • 23
  • Encoding the image increases the filesize by an average of 33%. Take a look at this study: http://davidbcalhoun.com/2011/when-to-base64-encode-images-and-when-not-to/ – andy Aug 23 '17 at 07:09