2

This is very basic requirement but did not get any result after research. In Swift 3.0, by using below API, we have saved captured image.

UIImageWriteToSavedPhotosAlbum

UIImage object have the image. Basic way to send image to server is convert the UIImage to NSData. To perform this below two API are available.

UIImageJPEGRepresentation //NOTE - We must specify the compression parameter.
UIImagePNGRepresentation // We don't need to specify the compression parameter.

By default, image saved is in JPEG format, we want to send SAME image to server WITHOUT any compression.

So size of jpeg image in album and size of image on server must be exactly same.

How do I achieve this ?

Thank you for help.

DJ-Glock
  • 1,277
  • 2
  • 12
  • 39
Banng
  • 531
  • 1
  • 6
  • 19
  • 1
    If the image is coming from the camera there is no compression. You have to decide which one to use. If you don't want any compression you can save it as PNG. Note that PNG will discard image rotation info. If you have the image data just send the original data. https://stackoverflow.com/a/43944769/2303865 – Leo Dabus Aug 29 '17 at 04:45
  • PNG file size is quite big for our application hence we are not considering that option. For e.g. JPG file size is around 470 KB, but PNG is around 4.5 MB. Hence we want to send as JPG file but UIImageJPEGRepresentation API have compression parameter, which we do NOT want to use. – Banng Aug 29 '17 at 05:11
  • You have no choice. When saving your image as jpeg you need to chose the compression rate. Just pass 1 for maximum quality. Another option is to fetch the image url asset (data) and send it to the server. check the link I posted above on how to get the original image data from photo library – Leo Dabus Aug 29 '17 at 05:16
  • Thanks for comments, Regarding another option you mentioned, actually "fetchImage" function returns UIImage, to send this UIImage to server, we have convert that to NSData. which leads to 2 options i.e. UIImageJPEGRepresentation ,UIImagePNGRepresentation. For JPEG, we have to send compression paramete, that is what we want to exclude. – Banng Aug 29 '17 at 05:33
  • if fetches the data. You don't need to create a UIImage from it. Not that hard to adjust it to your needs – Leo Dabus Aug 29 '17 at 05:33
  • Thank you. In fetchImage function, there is variable name data, you mean to say send this "data" direct as a POST, without converting to NSDATA ? – Banng Aug 29 '17 at 06:23
  • Are you working with Swift 3? Yes just send data. You are supposed to use Data instead of NSData in Swift 3.x and forward – Leo Dabus Aug 29 '17 at 06:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/153084/discussion-between-banng-and-leo-dabus). – Banng Aug 29 '17 at 06:33
  • 1
    Able to send "data" without jpeg or png compression. Thanks a lot. you rock ! – Banng Aug 30 '17 at 08:12

0 Answers0